Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2042434 | 1.4.0 | Neal Gafter | P3 | Closed | Fixed | beta3 |
Name: boT120536 Date: 04/11/2001
java version "1.3.1-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-beta-b15)
Java HotSpot(TM) Client VM (build 1.3.1beta-b15, mixed mode)
As per JLS 15.11.1, javac gives a compile time error when the identifier in a
field reference does not denote a field in the type of the qualifying primary
expression. However, don't you think a NullPointerException is a little harsh?
$ cat T15111i1.java
class T15111i1 {
static class A {
static class B {
static int i = 1;
}
}
int j = new A().B.i;
}
$ javac T15111i1.java
An exception has occurred in the compiler (1.3.1-beta). Please file a bug at
the Java Developer Connection (http://java.sun.com/cgi-bin/bugreport.cgi).
Include your program and the following diagnostic in your report. Thank you.
java.lang.NullPointerException
at com.sun.tools.javac.v8.comp.TransInner.access(TransInner.java:743)
at com.sun.tools.javac.v8.comp.TransInner._case(TransInner.java:1578)
at com.sun.tools.javac.v8.tree.Tree$Select.visit(Tree.java:963)
at com.sun.tools.javac.v8.tree.TreeTranslator.translate(TreeTranslator.java:35)
at com.sun.tools.javac.v8.comp.TransInner._case(TransInner.java:1572)
at com.sun.tools.javac.v8.tree.Tree$Select.visit(Tree.java:963)
at com.sun.tools.javac.v8.tree.TreeTranslator.translate(TreeTranslator.java:35)
at com.sun.tools.javac.v8.tree.TreeTranslator._case(TreeTranslator.java:106)
at com.sun.tools.javac.v8.tree.Tree$VarDef.visit(Tree.java:470)
at com.sun.tools.javac.v8.tree.TreeTranslator.translate(TreeTranslator.java:35)
at com.sun.tools.javac.v8.comp.TransInner._case(TransInner.java:1373)
at com.sun.tools.javac.v8.tree.Tree$ClassDef.visit(Tree.java:402)
at com.sun.tools.javac.v8.tree.TreeTranslator.translate(TreeTranslator.java:35)
at com.sun.tools.javac.v8.comp.TransInner.translate(TransInner.java:1335)
at com.sun.tools.javac.v8.comp.TransInner.translateTopLevelClass(TransInner.java:16
03)
at com.sun.tools.javac.v8.JavaCompiler.compile(JavaCompiler.java:397)
at com.sun.tools.javac.v8.Main.compile(Main.java:247)
at com.sun.tools.javac.Main.main(Main.java:16)
Also, notice that this variation gives an error message, but that the message is
totally unrelated to the required one (since B is not a field of type A):
$ cat T15111i1.java
class T15111i1 {
static class A {
static class B {
int i = 1;
}
}
int j = new A().B.i;
}
$ javac T15111i1.java
T15111i1.java:7: non-static variable i cannot be referenced from a static
context
int j = new A().B.i;
^
1 error
(Review ID: 120455)
======================================================================
- backported by
-
JDK-2042434 NullPointerException when compiling bad fieldaccess
-
- Closed
-
- duplicates
-
JDK-4525610 compiler generates error calling static method of static inner class
-
- Closed
-