r/programming • • Jun 05 '18

Code golfing challenge leads to discovery of string concatenation bug in JDK 9+ compiler

https://stackoverflow.com/questions/50683786/why-does-arrayin-i-give-different-results-in-java-8-and-java-10
2.2k Upvotes

355 comments sorted by

View all comments

Show parent comment

10

u/13steinj Jun 05 '18

On the other hand, I also wouldn't be surprised if it hasn't. Combined with the fact that JDK 9 was a relatively major change from 8 (modules, getting rid of the Observer pattern, so on), I don't think many companies would make the switch. In fact there are still some stuck on 6/7. That combined with

The issue seems to be limited to the string concatenation and assignment operator (+=) with an expression with side effect(s) as the left operand, like in array[test()]+="a", array[ix++]+="a", test()[index]+="a", or test().field+="a"

Makes it seem less likely to occur in production code that needs to readable and more like the OP's situation-- code golf.

2

u/duhace Jun 05 '18

it's sad this isn't more upvoted, since it's the best explanation i've seen so far making it clear why this was not caught.

2

u/13steinj Jun 06 '18

Thats what I get for being 6 hours late to the party.