-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.3.0
-
sparc
-
solaris_7
Name: laC46010 Date: 10/15/99
New javac (jdk1.3.0K) compiler doesn't report about illegal forward reference to
static variable in static inializers before variable's declaration. Note that
jdk1.3.0K 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.".
This bug was already filed as # 4262988. But after fixing jdk1.3.0K javac
doesn't find out another type of illegal forward reference in static
initializer.
See test source file and logs below.
-------------------------------------------------------- StatInit.java
class A {
static final int i1 = 333;
static final int i2 = 444;
static int i3;
static {
i3 = (unknown = i1 + i2); // compile-time error
}
static int unknown;
}
public class StatInit {
public static void main(String argv[])
{
A x = new A();
System.out.println("unknown = " + x.unknown);
System.out.println("i3 = " + x.i3);
}
}
-----------------------------------------------------------------------
Results of compilation:
novo83% /export/ld25/java/dest/jdk1.3.0K/solaris/bin/oldjavac StatInit.java
StatInit.java:6: Can't make forward reference to unknown in class A.
i3 = (unknown = i1 + i2); // compile-time error
^
1 error
novo83% /export/ld25/java/dest/jdk1.3.0K/solaris/bin/javac StatInit.java
novo83% echo $status
0
novo83% /export/ld25/java/dest/jdk1.3.0K/solaris/bin/java StatInit
unknown = 777
i3 = 777
novo83%
----------------------------------------------------------------------
======================================================================