langtools/test/tools/javac/7167125/DiffResultAfterSameOperationInnerClasses.java
author duke
Wed, 05 Jul 2017 18:59:39 +0200
changeset 18044 f1a01fb5f958
parent 16334 49b3f71982f6
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15712
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
     1
/*
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
     2
 * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
     4
 *
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
     7
 * published by the Free Software Foundation.
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
     8
 *
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    13
 * accompanied this code).
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    14
 *
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    18
 *
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    21
 * questions.
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    22
 */
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    23
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    24
/*
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    25
 * @test
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    26
 * @bug 7167125
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    27
 * @summary Two variables after the same operation in a inner class return
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    28
 * different results
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    29
 * @run main DiffResultAfterSameOperationInnerClasses
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    30
 */
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    31
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    32
public class DiffResultAfterSameOperationInnerClasses {
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    33
    public int i = 1;
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    34
    private int j = 1;
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    35
    public String s1 = "Hi, ";
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    36
    private String s2 = "Hi, ";
16334
49b3f71982f6 8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents: 15712
diff changeset
    37
    public int arr1[] = new int[]{1};
49b3f71982f6 8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents: 15712
diff changeset
    38
    public int arr2[] = new int[]{1};
15712
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    39
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    40
    public static void main(String[] args) {
16334
49b3f71982f6 8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents: 15712
diff changeset
    41
        DiffResultAfterSameOperationInnerClasses theTest =
49b3f71982f6 8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents: 15712
diff changeset
    42
                new DiffResultAfterSameOperationInnerClasses();
49b3f71982f6 8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents: 15712
diff changeset
    43
        InnerClass inner = theTest.new InnerClass();
49b3f71982f6 8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents: 15712
diff changeset
    44
        if (!inner.test1()) {
49b3f71982f6 8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents: 15712
diff changeset
    45
            throw new AssertionError("Different results after same calculation");
49b3f71982f6 8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents: 15712
diff changeset
    46
        }
49b3f71982f6 8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents: 15712
diff changeset
    47
49b3f71982f6 8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents: 15712
diff changeset
    48
        theTest.resetVars();
49b3f71982f6 8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents: 15712
diff changeset
    49
        if (!inner.test2()) {
15712
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    50
            throw new AssertionError("Different results after same calculation");
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    51
        }
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    52
    }
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    53
16334
49b3f71982f6 8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents: 15712
diff changeset
    54
    void resetVars() {
49b3f71982f6 8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents: 15712
diff changeset
    55
        i = 1;
49b3f71982f6 8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents: 15712
diff changeset
    56
        j = 1;
49b3f71982f6 8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents: 15712
diff changeset
    57
        s1 = "Hi, ";
49b3f71982f6 8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents: 15712
diff changeset
    58
        s2 = "Hi, ";
49b3f71982f6 8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents: 15712
diff changeset
    59
        arr1[0] = 1;
49b3f71982f6 8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents: 15712
diff changeset
    60
        arr2[0] = 1;
49b3f71982f6 8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents: 15712
diff changeset
    61
    }
49b3f71982f6 8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents: 15712
diff changeset
    62
15712
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    63
    class InnerClass {
16334
49b3f71982f6 8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents: 15712
diff changeset
    64
        public boolean test1() {
15712
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    65
            i += i += 1;
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    66
            j += j += 1;
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    67
16334
49b3f71982f6 8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents: 15712
diff changeset
    68
            arr1[0] += arr1[0] += 1;
49b3f71982f6 8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents: 15712
diff changeset
    69
            arr2[0] += arr2[0] += 1;
49b3f71982f6 8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents: 15712
diff changeset
    70
15712
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    71
            s1 += s1 += "dude";
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    72
            s2 += s2 += "dude";
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    73
16334
49b3f71982f6 8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents: 15712
diff changeset
    74
            return (i == j && i == 3 &&
49b3f71982f6 8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents: 15712
diff changeset
    75
                    arr1[0] == arr2[0] && arr2[0] == 3 &&
49b3f71982f6 8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents: 15712
diff changeset
    76
                    s1.equals(s2) && s1.endsWith("Hi, Hi, dude"));
49b3f71982f6 8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents: 15712
diff changeset
    77
        }
49b3f71982f6 8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents: 15712
diff changeset
    78
49b3f71982f6 8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents: 15712
diff changeset
    79
        public boolean test2() {
49b3f71982f6 8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents: 15712
diff changeset
    80
            (i) += (i) += 1;
49b3f71982f6 8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents: 15712
diff changeset
    81
            (j) += (j) += 1;
49b3f71982f6 8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents: 15712
diff changeset
    82
49b3f71982f6 8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents: 15712
diff changeset
    83
            (arr1[0])+= (arr1[0]) += 1;
49b3f71982f6 8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents: 15712
diff changeset
    84
            (arr2[0])+= (arr2[0]) += 1;
49b3f71982f6 8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents: 15712
diff changeset
    85
49b3f71982f6 8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents: 15712
diff changeset
    86
            (s1) += (s1) += "dude";
49b3f71982f6 8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents: 15712
diff changeset
    87
            (s2) += (s2) += "dude";
15712
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    88
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    89
            return (i == j && i == 3 &&
16334
49b3f71982f6 8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents: 15712
diff changeset
    90
                    arr1[0] == arr2[0] && arr2[0] == 3 &&
15712
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    91
                    s1.equals(s2) && s1.endsWith("Hi, Hi, dude"));
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    92
        }
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    93
    }
fa256e8cfe33 7167125: Two variables after the same operation in a inner class return different results
vromero
parents:
diff changeset
    94
}