4 ms·
> 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
by Terr_ 8y ago
> 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.
- reificator 8y agoI 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.
- gowld 8y agoIt'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 ...
- esrauch 8y agoThe same bug repros for array[method()] += "string"; where method is invoked twice instead of once.
- simias 8y agoIf 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.
- seandougall 8y agoEven 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.
- Dylan16807 8y agoDon't focus too much on the first example. array[i++] += "a" is just is broken. So is appending to array[foo()] or foo().field
- deleted 8y ago[deleted]
- java-man 8y agoI 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 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?
- kjeetgill 8y agoYea, 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.
- java-man 8y agothat's another gripe...
- kjeetgill 8y agoI 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 https://bugs.java.com/view_bug.do?bug_id=8154127
- java-man 8y agointeresting. 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.
- gurkendoktor 8y agoJavaFX 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.
- kjeetgill 8y agoIt'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.
- rhacker 8y agoNot 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.
- sctb 8y agoWe've updated the link from https://stackoverflow.com/q/50683786 https://stackoverflow.com/q/50683786 and the title from “Operator += is broken for Strings in Java 9 and 10” to the official issue page.
- oblong 8y ago> 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!