JDK-4332631 : java compiler throws NullPointerException when class can't be found.
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 1.3.0
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: other,linux,windows_nt
  • CPU: x86
  • Submitted: 2000-04-24
  • Updated: 2001-10-11
  • Resolved: 2000-06-23
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.4.0 merlinFixed
Related Reports
Duplicate :  
Description

Name: skR10017			Date: 04/24/2000



The test consists of three files that must be present to see the failure.
The file base.java must be placed into base subdirectory.
The sequence of compilation and CLASSPATH property is important.

Test fails in JDK 1.3.0beta for Linux and JDK 1.3beta-O for Solaris
----------------------------- base/base.java --------------------------------
public interface base
{
    public void run();
}
----------------------------- impl.java --------------------------------
public class impl implements base
{
    public void run()
    {  }
}
----------------------------- test.java --------------------------------
public class test extends impl {
  private String workdir="";
}
----------------------------- output ----------------------------------

[kotl@linux-4 test]$ ls -lR
.:
total 3
drwxrwxr-x   2 kotl     java          512 Apr 24 12:01 base
-rw-r--r--   1 kotl     java           71 Apr 24 12:00 impl.java
-rw-r--r--   1 kotl     java           66 Apr 24 12:00 test.java

base:
total 1
-rw-r--r--   1 kotl     java           49 Apr 24 12:00 base.java
[kotl@linux-4 test]$ cd base
[kotl@linux-4 base]$ export CLASSPATH=.
[kotl@linux-4 base]$ javac base.java
[kotl@linux-4 base]$ cd ..
[kotl@linux-4 test]$ export CLASSPATH=.:./base
[kotl@linux-4 test]$ javac impl.java
[kotl@linux-4 test]$ export CLASSPATH=.
[kotl@linux-4 test]$ javac test.java
test.java:2: cannot access base
file base.class not found
  private String workdir="";
          ^
An exception has occurred in the compiler (1.3.0beta). 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.Attr.check(Attr.java:81)
        at com.sun.tools.javac.v8.comp.Attr._case(Attr.java:1347)
        at com.sun.tools.javac.v8.tree.Tree$Literal.visit(Tree.java:1002)
        at com.sun.tools.javac.v8.comp.Attr.attribTree(Attr.java:234)
        at com.sun.tools.javac.v8.comp.Attr.attribExpr(Attr.java:254)
        at com.sun.tools.javac.v8.comp.Attr._case(Attr.java:402)
        at com.sun.tools.javac.v8.tree.Tree$VarDef.visit(Tree.java:470)
        at com.sun.tools.javac.v8.comp.Attr.attribTree(Attr.java:234)
        at com.sun.tools.javac.v8.comp.Attr.attribStat(Attr.java:276)
        at com.sun.tools.javac.v8.comp.Attr.attribClass(Attr.java:1415)
        at com.sun.tools.javac.v8.JavaCompiler.compile(JavaCompiler.java:378)
        at com.sun.tools.javac.v8.Main.compile(Main.java:247)
        at com.sun.tools.javac.Main.main(Main.java:16)
[kotl@linux-4 test]$
======================================================================

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

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: generic merlin FIXED IN: merlin merlin-beta INTEGRATED IN: merlin VERIFIED IN: merlin-beta3
14-06-2004

EVALUATION This appears to be an error recovery problem. When compiling 'test', the reference to 'impl' resolves without error, because 'impl' has been previously compiled to a class file. In fact, however, the classpath is corrupt, and the superinterface 'base' of 'impl' is not accessible. When we later need to query the superclass, the resolution fails, giving the error message indicated. Most likely, the stack backtrace is occurring because the code there expects the superclass link to be well-defined. In general, we cannot compile a class if the superclass is not present, but by changing the classpath as was done here, it is possible to compile a class in an environment in which its superclass could be found, only reference it later as a binary classfile in a situation in which the superclass cannot be found. The compiler should be robust against this possibility. william.maddox@Eng 2000-04-27
27-04-2000