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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 7
    • Fix Version/s: 8
    • Component/s: tools
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b78
    • CPU:
      x86
    • OS:
      windows_7
    • Verification:
      Verified

      Description

      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

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: