-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
1.2.1
-
sparc
-
solaris_2.4
Name: akC45999 Date: 04/01/99
The chapter 2.9.1 Field Modifiers of the revised JVMS reads:
A field can be declared final, in which case its declarator must include a
variable initializer (?2.9.2). Both class and instance variables (static and
non-static fields) may be declared final. Once a final field has been
initialized, it always contains the same value.
The test below shows that VM does not check neither if a final field
is initialized nor if it always contains the same value.
------------------------------ test.java ----------------------------
import java.io.PrintStream;
public class test {
public static void main(String a[]) {
BadClass.someMethod();
System.out.println("Bad");
}
}
---------------------------- BadClass.jasm --------------------------
public class BadClass
{
static final Field finalField:I;
public static Method someMethod:"()V"
stack 1 locals 0
{
iconst_0;
putstatic Field finalField:"I";
return;
}
}
---------------------------------------------------------------------
novo48% java -fullversion
java full version "JDK-1.2-V"
novo48% java test
Bad
======================================================================
======================================================================
Name: akC45999 Date: 04/01/99
There is more suitable test case:
------------------------------ test.java ----------------------------
import java.io.PrintStream;
public class test {
public static void main(String a[]) {
BadClass.someMethod(1);
System.out.println("finalField = " + BadClass.finalField);
BadClass.someMethod(2);
System.out.println("finalField = " + BadClass.finalField);
}
}
---------------------------- BadClass.jasm --------------------------
public class BadClass
{
static final Field finalField:I;
public static Method someMethod:"(I)V"
stack 1 locals 1
{
iload_0;
putstatic Field finalField:"I";
return;
}
}
---------------------------------------------------------------------
novo48% java test
finalField = 1
finalField = 2
======================================================================
- relates to
-
JDK-4132650 Description of "final" access bit for fields is not full.
- Closed