RFR: 8204322: "+=" applied to String operands can provoke side effects

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Wed Jun 6 14:05:51 UTC 2018


Looks solid!

Thanks for everybody involved in the fix.

Cheers
Maurizio


On 06/06/18 14:23, Vicente Romero wrote:
> 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/d5fc2a71/attachment.html>


More information about the compiler-dev mailing list