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

circular reference error in static inializers is not reported

XMLWordPrintable

    • kestrel
    • sparc
    • solaris_7



      Name: laC46010 Date: 08/17/99



      New JDK1.3 compiler doesn't report about illegal forward reference to static
      variable in static inializers before variable's declaration. Note that JDK1.3
      oldjavac compiler correctly reports the error. Corresponding assertion in JLS
      8.5 (p.175) is:
      "The static initializers may not refer to class variables
      declared in the class whose declarations appear textually after
      the use, even though these class variables are in scope. This
      restriction is designed to catch, at compile time, circular or
      otherwise malformed initializations.".

      See reduced variant of "clss19104" JCK test and logs below.

      ----------------------------------------------------------------clss19104.java
      class clss19104 {
        static int i,j;
        static {
          j = i - 1;
          i = j < 0 ? k - 2: 1; // compile-time error
        }
        static int k = j + 3;
        public static void main(String argv[])
        {
           System.out.println("i= " + i);
           System.out.println("j= " + j);
           System.out.println("k= " + k);
        }
      }
      -----------------------------------------------------------------------------
      Results of compilation:

      novo37% /export/ld25/java/dest/jdk1.3N/solaris/bin/javac -d . clss19104.java
      novo37% echo $status
      0
      novo37% /export/ld25/java/dest/jdk1.3N/solaris/bin/oldjavac -d .
      clss19104.java
      clss19104.java:5: Can't make forward reference to k in class clss19104.
          i = j < 0 ? k - 2: 1; // compile-time error
                      ^
      1 error
      novo37% echo $status
      1
      novo37%
      -------------------------------------------------------------------------------

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

            wmaddoxsunw William Maddox (Inactive)
            leosunw Leo Leo (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: