RFR: 8204322: "+=" applied to String operands can provoke side effects
Vicente Romero
vicente.romero at oracle.com
Wed Jun 6 13:23:50 UTC 2018
Please review the fix for [1] at [2]. Javac was generating incorrect
code for the case when the `+=` operand was applied to Strings and it is
visible for test cases like:
public class Test {
static int test() {
System.out.println("evaluated");
return 0;
}
public static void main(String[] args) {
String[] array = {""};
array[test()] += "a";
}
}
the string "evaluated" is printed twice. Some items were missing in the
stack, the solution is to duplicate those missing items plus not to
evaluate the lhs expression twice.
Thanks in advance for the comments,
Vicente
Thanks to Aleksey Shipilev for the great regression test.
[1] https://bugs.openjdk.java.net/browse/JDK-8204322
[2] http://cr.openjdk.java.net/~vromero/8204322/webrev.01/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20180606/f2876263/attachment.html>
More information about the compiler-dev
mailing list