Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7167125

Two variables after the same operation in a inner class return different results

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 8
    • 7
    • tools
    • b78
    • x86
    • windows_7
    • Verified

      FULL PRODUCT VERSION :
      java version "1.7.0_04"
      Java(TM) SE Runtime Environment (build 1.7.0_04-b22)
      Java HotSpot(TM) 64-Bit Server VM (build 23.0-b21, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Windows 7 Ultimate 64 bits SP1

      A DESCRIPTION OF THE PROBLEM :
      The access attributes affected the results of the operation.

      The results of the below code printed:
      i = 3
      j = 4

      ==================================================
      public class outer {
          public int i = 1;
          private int j = 1;
         
          public static void main(String[] args) {
              new outer().new inner().Test();
          }
          
          class inner {
              public void Test() {
                  i+=i+=1;
                  j+=j+=1;

                  System.out.println("i = " + i);
                  System.out.println("j = " + j);
              }
          }
      }

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      If the access attributes of the i and j are public, the results are 3
      If the access attributes of the i and j are private, the results are 4
      If the access attributes of the i and j are public and private respectively, the results are 3 and 4

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The expected result:
      i = 3
      j = 3
      ACTUAL -
      The actual results:
      i = 3
      j = 4

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class outer {
          public int i = 1;
          private int j = 1;
         
          public static void main(String[] args) {
              new outer().new inner().Test();
          }
          
          class inner {
              public void Test() {
                  i+=i+=1;
                  j+=j+=1;

                  System.out.println("i = " + i);
                  System.out.println("j = " + j);
              }
          }
      }
      ---------- END SOURCE ----------

      SUPPORT :
      YES

            vromero Vicente Arturo Romero Zaldivar
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: