runtime: String.Join(string, object[]) bug when first item is null

Continuing my series to break the BCL for fun and no profit here’s another string.Join bug:

String.Join(",", new object[] { null, "x" })

returns "". It should return ",x".

This bug exists in CoreCLR, in 4.6.2 and in the recently merged string.Join fix.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 3
  • Comments: 17 (15 by maintainers)

Most upvoted comments

IMO I think this should be fixed for .NET Core; this behavior is unintuitive, especially considering the fact that if you cast to IEnumerable<object> (or cast to object[] from string[], since arrays are covariant) you will get different behavior. This makes it very hard to write technically correct code.

@jkotas, you mentioned in the Tuple PR that commits that may cause compatibility issues with the desktop are simply not cherry-picked. Would it make sense to remove the bug now and fix the documentation? (It is preventing me from sharing code with the new char-based Join overloads-- see https://github.com/dotnet/coreclr/pull/7942#issuecomment-257735623

@bbowyersmyth oh no! Haha that is so unfortunate.

It’s a documented bug so that makes it a feature 😉 https://msdn.microsoft.com/en-us/library/dd988350(v=vs.110).aspx

@jkotas What is the viewpoint on quirking old bugs on the new core platforms?