StringJoiner: detect or fix delimiter collision?

Steven Schlansker stevenschlansker at
Tue Jul 23 20:56:34 UTC 2013

On Jul 23, 2013, at 1:37 PM, ph <philip.hodges at> wrote:

> The omission of that very complexity is a copious source of bugs that breaks
> applications in production, and is extremely useful and interesting to the
> black hat community.
> It should not be possible to call a joiner without escaping or quoting or
> catching an exception or explicitly waiving the complexity. Of course there
> will still be some users who roll their own, blissfully unaware of the
> existence of StringJoiner. But for those who do discover it, the important
> value to add is not convenience, but safety.
> Maybe you could even retrofit it to Arrays.toString(), which is exactly such
> a toy interface only good for things like logging where delimiter collision
> doesn't usually matter.
> At the very least can you please cover it in the examples so that people
> can't completely overlook it?


If you are expecting to read the data back in a structured manner, I would expect you to use a proper structured format e.g. CSV or JSON, not a simple string joiner.  String joining seems to work the same in every language I see (Python, Ruby, Javascript at least) and given that it takes arbitrary (potentially multi-character) delimiters I'm not even sure what behavior you'd expect that could make sense with any given delimiter.

The current behavior is similar to other languages, simple to understand, and seems to not be "surprising" to most people.

Why would you not write your data out as e.g. JSON?  Then all of the tricky cases are handled correctly for you.


More information about the core-libs-dev mailing list