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

wrong evaluation order of assignment expressions

XMLWordPrintable

    • rc
    • generic, sparc
    • solaris_2.4, solaris_8



      Name: swC45995 Date: 11/06/96


      The right-hand operand of an assignment expression is evaluated prior
      to evaluation of the left-hand operand. It contradicts the following
      assertion:

      First, the left-hand operand is evaluated to produce a variable. If this evaluation completes abruptly, then the assignment expression completes abruptly for the same reason; the right-hand operand is not evaluated and no assignment occurs. (Java Language Specification, section 15.25.1 Simple Assignment
      Operator)

      Thus, execution of the following test

      public class test
      {
      int field;

      public static void main(String argv[])
      {
      test x = null;
      int a = 0;

      try {
      x.field = ++a;
      } catch (NullPointerException e) {
      System.out.println(a);
      }
      }
      }

      produces such output:

      novo40% java test
      1

      instead of expected:

      novo40% java test
      0

      ======================================================================

            gbrachasunw Gilad Bracha (Inactive)
            wensunw Wen Wen (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: