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

Vicente Romero vicente.romero at oracle.com
Wed Jun 6 14:19:36 UTC 2018


On 06/06/2018 10:05 AM, Maurizio Cimadamore wrote:
>
> Looks solid!
>
> Thanks for everybody involved in the fix.
>

yep, thanks, great teamwork!

> Cheers
> Maurizio
>

Vicente

>
> 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/969a1d86/attachment-0001.html>


More information about the compiler-dev mailing list