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

Jan Lahoda jan.lahoda at oracle.com
Wed Jun 6 14:05:47 UTC 2018


Looks good to me.

Jan

On 6.6.2018 15: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/
>


More information about the compiler-dev mailing list