News for hackers. Stuff that matters.
Re:Java: "+=" applied to String operands can provoke side ef... by Terr_ on Wednesday June 06, 2018 @12:29PM (#17248517)
> Operator += is broken for Strings in Java 9 and 10

The title [Edit: since changed] is a little bit fear-monger-y. It's only broken when the left hand side is not safe to evaluate more than once.

It can be prevented with a compile-time flag.

Re:Java: "+=" applied to String operands can provoke side ef... by java-man on Wednesday June 06, 2018 @12:42PM (#17248667)
I think it's a big deal: introduced in 9 and fixed in 11? It suggests two things: Oracle has gaps in the regression test suite, and they don't consider compiler error such as these as a big issue.

Java 9 broke other things. Here is one: https://github.com/andy-goryachev/FxDock/issues/8 WebView is working fine in 8, totally broken in 9, partially broken in 10. Do they have a QA department?

Re:Java: "+=" applied to String operands can provoke side ef... by kjeetgill on Wednesday June 06, 2018 @12:48PM (#17248719)
Yea, I'm surprised the infamous TCK regression suite didn't include something so fundamental.

That said, javafx is a bit of an orphan compared the rest of the JDK. And that's why it's getting pushed out.

Re:Java: "+=" applied to String operands can provoke side ef... by java-man on Wednesday June 06, 2018 @12:53PM (#17248769)
that's another gripe...
Re:Java: "+=" applied to String operands can provoke side ef... by kjeetgill on Wednesday June 06, 2018 @01:12PM (#17248968)
I don't know if this is your issue but in a minor Java 8 release, the JavaFX team made all references held by a webview's JS weak references.

What a dramatic change over what seems to be a solvable memory leak. I only toyed with JavaFX but at least it's webview is dead to me.

See: https://bugs.java.com/view_bug.do?bug_id=8154127

Re:Java: "+=" applied to String operands can provoke side ef... by java-man on Wednesday June 06, 2018 @01:25PM (#17249094)
interesting. no, it is not my issue - in my case nothing gets rendered in WebView, the view stays blank.

and another thing - how does one submit a defect report to Oracle? neither bugs.openjdk.java.net nor bugs.java.com have a clear link, and I can't find where one can register an account.

Re:Java: "+=" applied to String operands can provoke side ef... by gurkendoktor on Wednesday June 06, 2018 @06:58PM (#17251840)
JavaFX HiDPI support on Windows also underwent breaking changes in minor Java 8 updates. It's probably for the best that JavaFX can have its own, independent version number now that it was kicked out of the JDK.
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.
Re:Java: "+=" applied to String operands can provoke side ef... by rhacker on Wednesday June 06, 2018 @01:17PM (#17249015)
Not so sure about that... let's say this bug is causing a minor inconsistency in any one of the thousands of databases built on top of Java, not the least one of the most popular databases Elasticsearch. We may not know yet, but this bug could theoretically be causing different output. In fact if we see anything from the Lucene project related to this bug, then we know for sure ES and other products are likely affected.
Re:Java: "+=" applied to String operands can provoke side ef... by kjeetgill on Wednesday June 06, 2018 @12:43PM (#17248675)
It's easy to work around, sure, but it's still going to be something that's hard to catch if you see it in the wild.

Also: it only breaks when it's an array of Strings.

Re:Java: "+=" applied to String operands can provoke side ef... by sctb on Wednesday June 06, 2018 @01:44PM (#17249300)
We've updated the link from https://stackoverflow.com/q/50683786 and the title from “Operator += is broken for Strings in Java 9 and 10” to the official issue page.
Re:Java: "+=" applied to String operands can provoke side ef... by oblong on Wednesday June 06, 2018 @03:08PM (#17250084)
> It's only broken when the left hand side is not safe to evaluate more than once.

The brakes on my car aren't broken most of the time, it's only when I push down on the pedal!