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

     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, ";
    38     public static void main(String[] args) {
    39         InnerClass inner =
    40                 new DiffResultAfterSameOperationInnerClasses().new InnerClass();
    41         if (!inner.test()) {
    42             throw new AssertionError("Different results after same calculation");
    43         }
    44     }
    46     class InnerClass {
    47         public boolean test() {
    48             i += i += 1;
    49             j += j += 1;
    51             s1 += s1 += "dude";
    52             s2 += s2 += "dude";
    54             System.out.println("s1 = " + s1);
    55             System.out.println("s2 = " + s2);
    57             return (i == j && i == 3 &&
    58                     s1.equals(s2) && s1.endsWith("Hi, Hi, dude"));
    59         }
    60     }
    61 }

mercurial