United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6703334 javac NPE in Check$Validator.visitSelect
JDK-6703334 : javac NPE in Check$Validator.visitSelect

Details
Type:
Bug
Submit Date:
2008-05-16
Status:
Resolved
Updated Date:
2011-02-16
Project Name:
JDK
Resolved Date:
2009-02-09
Component:
tools
OS:
solaris_7
Sub-Component:
javac
CPU:
sparc
Priority:
P2
Resolution:
Fixed
Affected Versions:
1.4.2_18
Fixed Versions:
1.4.2_19-rev (b09)

Related Reports
Backport:
Backport:

Sub Tasks

Description
Description: 1.4.2 javac NPE in Check$Validator.visitSelect

 FULL PRODUCT VERSION :
./java -version
java version "1.4.2_14"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_14-b03) Java
HotSpot(TM) Client VM (build 1.4.2_14-b03, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
SunOS 5.8 Generic_108528-14 sun4u sparc SUNW,Ultra-4

A DESCRIPTION OF THE PROBLEM :
  Verified this NPE happens when following conditions are met.

- The class in the java source being compiled (A) implements an interface
(B)
  whose super class (interface) is not visible during compilation.
- .class exists for the interface (B) above.
- (A) implements another interface that is in a package.

This problem happens on JDK 1.4.2_* on Solaris and Windows.

myc.java	(A)
myitf/myitf.java	// interface which (B) extends
myitf/myitf.class	//
myitf2.class	(B) .class
myitf2.java	(B)

$ find . -name '*.java' | xargs pg | cat
::::::::::::::
./myc.java
::::::::::::::
public final class myc implements myitf2, java.io.Serializable {

}
::::::::::::::
./myitf/myitf.java
::::::::::::::
public interface myitf {
  final int VAR = 1;
}
::::::::::::::
./myitf2.java
::::::::::::::
public interface myitf2 extends myitf {
  public abstract void methodA();
}



$ <jdk1.4.2_14>/bin/javac myc.java
myc.java:1: cannot access myitf
file myitf.class not found
public final class myc implements myitf2, java.io.Serializable {
             ^
An exception has occurred in the compiler (1.4.2_14). Please file a bug at
the Java Developer Connection (http://java.sun.com/cgi-bin/bugreport.cgi)
after checking the Bug Parade for duplicates. Include your program and the
following diagnostic in your report.  Thank you.
java.lang.NullPointerException
        at
com.sun.tools.javac.v8.comp.Check$Validator.visitSelect(Check.java:437)
        at com.sun.tools.javac.v8.tree.Tree$Select.accept(Tree.java:1091)
        at com.sun.tools.javac.v8.comp.Check.validate(Check.java:409)
        at com.sun.tools.javac.v8.comp.Check.validate(Check.java:420)
        at com.sun.tools.javac.v8.comp.Attr.attribClassBody(Attr.java:1369)
        at com.sun.tools.javac.v8.comp.Attr.attribClass(Attr.java:1356)
        at com.sun.tools.javac.v8.comp.Attr.attribClass(Attr.java:1332)
        at
com.sun.tools.javac.v8.JavaCompiler.compile(JavaCompiler.java:355)
        at com.sun.tools.javac.v8.Main.compile(Main.java:569)
        at com.sun.tools.javac.Main.compile(Main.java:36)
        at com.sun.tools.javac.Main.main(Main.java:27)

The problem is not seen with jdk 1.5 :
$ <jdk1.5.0_12>/bin/javac myc.java
myc.java:1: cannot access myitf
file myitf.class not found
public final class myc implements myitf2, java.io.Serializable {
             ^

                                    

Comments
SUGGESTED FIX

--- src/share/javac/com/sun/tools/javac/v8/Main.java-	2008-02-01 20:34:43.000000000 +0300
+++ src/share/javac/com/sun/tools/javac/v8/Main.java	2008-06-19 21:56:33.177999786 +0400
@@ -586,7 +586,12 @@
             return EXIT_SYSERR;
         }
         catch (Throwable ex) {
-            bugMessage(ex);
+            // If we've already reported an error, compensate for
+            // buggy compiler error recovery by swallowing thrown
+            // exceptions.
+            if (comp == null || comp.errorCount() == 0 ||
+                options == null || options.get("dev") != null)
+                bugMessage(ex);
             return EXIT_ABNORMAL;
         }
         finally { if (comp != null)
                                     
2008-06-19
EVALUATION

Thrown exception is valid, although as we've already reported an error,
we should not print it, but silently exit.

Please find suggested fix attached; it brings javac in 1.4.2 in line with
1.5.0's one.
                                     
2008-06-19



Hardware and Software, Engineered to Work Together