News for hackers. Stuff that matters.
Re:Java: "+=" applied to String operands can provoke side ef... by reificator on Wednesday June 06, 2018 @12:37PM (#17248599)
I mean, that's fairly broken given the way developers expect operators to be applied.

The ease of avoidance is unrelated to whether it's broken behavior or not.

Re:Java: "+=" applied to String operands can provoke side ef... by gowld on Wednesday June 06, 2018 @01:06PM (#17248908)
It's a bug for sure, but anyone who cares about correctness ought to be using a style that doesn't allow this tortured contortion:

  array[i++] += i ...
Re:Java: "+=" applied to String operands can provoke side ef... by simias on Wednesday June 06, 2018 @01:19PM (#17249032)
If I understand correctly "array[i++] += ..." alone is enough to trigger the bug which doesn't seem particularly tortured to me. Actually any "array[side_effect()] +=" would trigger the bug. That's pretty bad IMO.
Re:Java: "+=" applied to String operands can provoke side ef... by seandougall on Wednesday June 06, 2018 @03:46PM (#17250444)
Even if the function within the subscript were free if side effects, calling it twice would be a ridiculous performance regression. I’m no compiler developer, but this really seems like a rookie mistake.
Re:Java: "+=" applied to String operands can provoke side ef... by Dylan16807 on Wednesday June 06, 2018 @01:19PM (#17249035)
Don't focus too much on the first example.

  array[i++] += "a"
is just is broken. So is appending to array[foo()] or foo().field
Re:Java: "+=" applied to String operands can provoke side ef... by esrauch on Wednesday June 06, 2018 @01:18PM (#17249018)
The same bug repros for array[method()] += "string"; where method is invoked twice instead of once.