StringJoiner: detect or fix delimiter collision?

Henry Jen henry.jen at oracle.com
Thu Jan 30 23:49:46 UTC 2014


On 01/27/2014 12:31 PM, Philip Hodges wrote:
> I did not predict that it would be a "sprintf". It's not going to be consistently misused anything like so frequently.
> I compared it to the unescaped XML generation antipattern.
>
> I have not seen any technical justifications whatsoever so far, just inexplicable enthusiasm.
>
> It is like giving young drivers a faster car with no seat belts.
>

As Mike had said, delimiter collision is a valid concern, and I think 
your metaphore is quite vivid.

Anyhow, there is need for fast and simply join operation, and this is 
what JDK is intend to provide. Nothing prohibit developer to
- choose a better delimiter for the data
- escape the element before sending to joiner

Since we expect more complicate use case is more likely to be used in 
stream API, such escaping can be easily done by adding a map step.

elements.stream()
         .map(escapeFunction)
	.collect(joining())

Cheers,
Henry




More information about the core-libs-dev mailing list