United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6889255 javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
JDK-6889255 : javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly

Details
Type:
Bug
Submit Date:
2009-10-07
Status:
Closed
Updated Date:
2012-07-03
Project Name:
JDK
Resolved Date:
2012-01-13
Component:
tools
OS:
generic,windows_7
Sub-Component:
javac
CPU:
x86,generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
6u31,7
Fixed Versions:

Related Reports
Backport:
Duplicate:
Relates:
Relates:

Sub Tasks

Description
When core classes are built for debug (-g flag) javah throws an unexpected
java.lang.NullPointerException while working in jdk/make/java/nio:

An exception has occurred in the compiler (1.7.0-tbell_2009_10_05.23.59.01_bootstrap). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport)  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.code.Symbol$MethodSymbol.params(Symbol.java:1226)
        at com.sun.tools.javac.code.Symbol$MethodSymbol.getParameters(Symbol.java:1252)
        at com.sun.tools.javac.code.Symbol$MethodSymbol.getParameters(Symbol.java:1014)
        at javax.lang.model.util.ElementScanner6.visitExecutable(ElementScanner6.java:191)
        at com.sun.tools.javac.code.Symbol$MethodSymbol.accept(Symbol.java:1260)
        at javax.lang.model.util.ElementScanner6.scan(ElementScanner6.java:139)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment$ComputeAnnotationSet.scan(JavacProcessingEnvironment.java:767)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment$ComputeAnnotationSet.scan(JavacProcessingEnvironment.java:745)
        at javax.lang.model.util.ElementScanner6.scan(ElementScanner6.java:129)
        at javax.lang.model.util.ElementScanner6.visitType(ElementScanner6.java:169)
        at com.sun.tools.javac.code.Symbol$ClassSymbol.accept(Symbol.java:874)
        at javax.lang.model.util.ElementScanner6.scan(ElementScanner6.java:139)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment$ComputeAnnotationSet.scan(JavacProcessingEnvironment.java:767)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment$ComputeAnnotationSet.scan(JavacProcessingEnvironment.java:745)
        at javax.lang.model.util.ElementScanner6.scan(ElementScanner6.java:129)
        at javax.lang.model.util.ElementScanner6.visitType(ElementScanner6.java:169)
        at com.sun.tools.javac.code.Symbol$ClassSymbol.accept(Symbol.java:874)
        at javax.lang.model.util.ElementScanner6.scan(ElementScanner6.java:139)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment$ComputeAnnotationSet.scan(JavacProcessingEnvironment.java:767)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:825)
        at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1070)
        at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:805)
        at com.sun.tools.javac.main.Main.compile(Main.java:400)
        at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:139)
        at com.sun.tools.javah.JavahTask.run(JavahTask.java:482)
        at com.sun.tools.javah.JavahTask.run(JavahTask.java:319)
        at com.sun.tools.javah.Main.main(Main.java:46)


Bug-ID 6888888 is the short term workaround, which is to use the bootstrap javah instead.

This bug report is for the eventual fix.

                                    

Comments
SUGGESTED FIX

When the time comes, part of this fix needs to be removing the
workaround added to jdk/make/common/shared/Defs-java.gmk
under 6888888:

*** 163,172 ****
--- 163,177 ----
    JAVAH_CMD     = $(JAVA_TOOLS_DIR)/javah \
                    $(JAVAHFLAGS)
    JAVADOC_CMD   = $(JAVA_TOOLS_DIR)/javadoc $(JAVA_TOOLS_FLAGS:%=-J%)
  endif
  
+ #always use the bootstrap javah until bug-ID 6889255 is fixed.  These
+ #five lines should be removed as part of that fix:
+ JAVAH_CMD     = $(JAVA_TOOLS_DIR)/javah \
+                   $(JAVAHFLAGS)
+ 
  # Override of what javac to use (see deploy workspace)
  ifdef JAVAC
    JAVAC_CMD     = $(JAVAC)
  endif
                                     
2009-10-07
EVALUATION

The problem is actually in javac, not javah per se.

Fundamentally, the problem is in javac ClassReader, which is not correctly reading the saved parameter names. It reads too few names, which causes an NPE in MethodSymbol when using iterators to correlate the list of names with the list of parameters.

There are many things wrong in the ClassReader code:

1) the main reason causing the observed NPE is that the name reading code does not take into account the adjustment to the MethodType in readMethod to ignore the synthetic parameter this$0.  Given this error, it then fails to correctly match up names to parameters.

2) the name reading code assumes a single LocalVariableTable (which is not required)

3) the name reading code assumes that all the parameters are named (which is not required)

4) the name reading code assumes that the parameters are named in order (which is not required)

These are all long-standing issues and not the result of any recent changes.   The issue with javah is just that by using annotation processing, it is tickling these bugs in ClassReader.
                                     
2009-10-08



Hardware and Software, Engineered to Work Together