-
Bug
-
Resolution: Fixed
-
P2
-
1.2.0
-
1.2beta3
-
sparc
-
solaris_2.5.1
-
Verified
Name: laC46010 Date: 11/06/97
According to specs a call of an interface method is not an active use
of the interface and should not cause initialization of the interface.
However JDK (all 1.1.x and 1.2 but not 1.0.2) does initialize the
interface "inter" in the example below. See also original JCK test case:
vm/constantpool/InterfMethod/InterfMethod001/InterfMethod00101/InterfMethod00101.html
JVM spec [2.16.4 Initialization, p.46] and
JLS [12.4.1 When Initialization Occurs, p.223] say:
"A class or interface type T will be initialized at its first active use,
which occurs if:
* T is a class and a method actually declared in T (rather than inherited
from a superclass) is invoked.
* T is a class and a constructor for class T is invoked.
* A nonconstant field declared in T (rather than inherited from a
superclass or superinterface) is used or assigned. A constant field is
one that is (explicitly or implicitly) both final and static, and that
is initialized with the value of a compile-time constant expression.
Java specifies that a reference to such a field must be resolved at
compile time to a copy of the compile-time constant value, so uses of
such field are never active uses."
It means that i.foo() is not an active use and should not cause
initialization of "inter" interface and its field "x" causing
loading and initialization of class "c2". See however behaviour
of JDK1.1.x-JDK1.2:
> /export/ld14/java/dest/jdk1.2/solaris/bin/java c
java.lang.Error: Failed: illegal initialization of c2
at c2.val(c.java:23)
at
at
Note that jdk1.0.2 behaviour conforms to the specs:
> /export/ld32/jdk_1.0.2/bin/java c
Passed: catched java.lang.NullPointerException
--------------------------------c.java----------------------------------
public class c {
public static void main(String argv[]) {
inter i = null;
try {
i.foo();
} catch (java.lang.NullPointerException e) {
System.out.println("Passed: catched " + e);
}
}
}
interface inter {
final int x = c2.var + c2.val();
void foo();
}
class c2 {
static int var = 111;
static int val() {
if (var == 111)
throw new Error("Failed: illegal initialization of c2");
else
return 222;
}
}
-----------------------------------------------------------------------
Hook 5(hook5): test
======================================================================