test/tools/javac/7167125/DiffResultAfterSameOperationInnerClasses.java

Fri, 08 Feb 2013 09:21:19 +0000

author
vromero
date
Fri, 08 Feb 2013 09:21:19 +0000
changeset 1557
017e8bdd440f
child 1621
823fb9229724
permissions
-rw-r--r--

7167125: Two variables after the same operation in a inner class return different results
Reviewed-by: jjg, mcimadamore

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

mercurial