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