8159439: javac throws NPE with Module attribute and super_class != 0
authorvromero
Mon, 27 Jun 2016 12:29:41 -0700
changeset 39361 cd0aca7db174
parent 39184 3aa52182b3ad
child 39362 5ac5af2acb57
8159439: javac throws NPE with Module attribute and super_class != 0 Reviewed-by: jjg
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties
langtools/test/ProblemList.txt
langtools/test/tools/javac/diags/examples.not-yet.txt
langtools/test/tools/javac/modules/T8159439/NPEForModuleInfoWithNonZeroSuperClassTest.java
langtools/test/tools/javac/modules/T8159439/NPEForModuleInfoWithNonZeroSuperClassTest.out
langtools/test/tools/javac/modules/T8159439/module-info.jcod
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java	Wed Jul 05 21:53:18 2017 +0200
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java	Mon Jun 27 12:29:41 2016 -0700
@@ -50,6 +50,7 @@
 import javax.tools.JavaFileObject.Kind;
 import javax.tools.StandardLocation;
 
+import com.sun.tools.javac.code.ClassFinder;
 import com.sun.tools.javac.code.Directive;
 import com.sun.tools.javac.code.Directive.ExportsDirective;
 import com.sun.tools.javac.code.Directive.RequiresDirective;
@@ -101,6 +102,8 @@
 
 import com.sun.tools.javac.tree.JCTree.JCDirective;
 import com.sun.tools.javac.tree.JCTree.Tag;
+import com.sun.tools.javac.util.Abort;
+import com.sun.tools.javac.util.Position;
 
 import static com.sun.tools.javac.code.Flags.ABSTRACT;
 import static com.sun.tools.javac.code.Flags.ENUM;
@@ -217,6 +220,9 @@
             for (ModuleSymbol msym: roots) {
                 msym.complete();
             }
+        } catch (CompletionFailure ex) {
+            log.error(JCDiagnostic.DiagnosticFlag.NON_DEFERRABLE, Position.NOPOS, "cant.access", ex.sym, ex.getDetailValue());
+            if (ex instanceof ClassFinder.BadClassFile) throw new Abort();
         } finally {
             depth--;
         }
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java	Wed Jul 05 21:53:18 2017 +0200
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java	Mon Jun 27 12:29:41 2016 -0700
@@ -2418,6 +2418,9 @@
         // reset and read rest of classinfo
         bp = startbp;
         int n = nextChar();
+        if ((flags & MODULE) != 0 && n > 0) {
+            throw badClassFile("module.info.invalid.super.class");
+        }
         if (ct.supertype_field == null)
             ct.supertype_field = (n == 0)
                 ? Type.noType
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties	Wed Jul 05 21:53:18 2017 +0200
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties	Mon Jun 27 12:29:41 2016 -0700
@@ -1850,6 +1850,9 @@
 compiler.misc.class.file.wrong.class=\
     class file contains wrong class: {0}
 
+compiler.misc.module.info.invalid.super.class=\
+    module-info with invalid super class
+
 compiler.misc.class.file.not.found=\
     class file for {0} not found
 
--- a/langtools/test/ProblemList.txt	Wed Jul 05 21:53:18 2017 +0200
+++ b/langtools/test/ProblemList.txt	Mon Jun 27 12:29:41 2016 -0700
@@ -76,6 +76,7 @@
 tools/javac/annotations/typeAnnotations/referenceinfos/Lambda.java              8057687    generic-all    emit correct byte code an attributes for type annotations
 tools/javac/annotations/typeAnnotations/referenceinfos/NestedTypes.java         8057687    generic-all    emit correct byte code an attributes for type annotations
 tools/javac/warnings/suppress/TypeAnnotations.java                              8057683    generic-all    improve ordering of errors with type annotations
+tools/javac/modules/T8159439/NPEForModuleInfoWithNonZeroSuperClassTest.java     8160396    generic-all    current version of jtreg needs a new promotion to include lastes version of ASM
 
 ###########################################################################
 #
--- a/langtools/test/tools/javac/diags/examples.not-yet.txt	Wed Jul 05 21:53:18 2017 +0200
+++ b/langtools/test/tools/javac/diags/examples.not-yet.txt	Mon Jun 27 12:29:41 2016 -0700
@@ -120,6 +120,7 @@
 compiler.misc.bad.module-info.name                            # bad class file
 compiler.err.locn.bad.module-info                             # bad class file
 compiler.err.locn.cant.read.file                              # bad class file
+compiler.misc.module.info.invalid.super.class                 # bad class file
 compiler.err.locn.cant.read.directory                         # file system issue
 compiler.misc.unnamed.module                                  # fragment uninteresting in and of itself
 compiler.misc.kindname.module                                 # fragment uninteresting in and of itself
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/modules/T8159439/NPEForModuleInfoWithNonZeroSuperClassTest.java	Mon Jun 27 12:29:41 2016 -0700
@@ -0,0 +1,9 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8159439
+ * @summary javac throws NPE with Module attribute and super_class != 0
+ * @build module-info
+ * @compile/fail/ref=NPEForModuleInfoWithNonZeroSuperClassTest.out -XDrawDiagnostics NPEForModuleInfoWithNonZeroSuperClassTest.java
+ */
+
+class NPEForModuleInfoWithNonZeroSuperClassTest {}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/modules/T8159439/NPEForModuleInfoWithNonZeroSuperClassTest.out	Mon Jun 27 12:29:41 2016 -0700
@@ -0,0 +1,2 @@
+- compiler.err.cant.access: mod.module-info, (compiler.misc.bad.class.file.header: module-info.class, (compiler.misc.module.info.invalid.super.class))
+1 error
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/modules/T8159439/module-info.jcod	Mon Jun 27 12:29:41 2016 -0700
@@ -0,0 +1,55 @@
+module mod {
+  0xCAFEBABE;
+  0; // minor version
+  53; // version
+  [] { // Constant Pool
+    ; // first element is empty
+    Utf8 "mod/module-info"; // #1    
+    class #1; // #2    
+    Utf8 "java/lang/Object"; // #3    
+    class #3; // #4    
+    Utf8 "java.base"; // #5    
+    Utf8 "pkg"; // #6    
+    Utf8 "Module"; // #7    
+    Utf8 "Version"; // #8    
+    Utf8 "6.0"; // #9    
+  } // Constant Pool
+
+  0x8000; // access
+  #2;// this_cpx
+  #4;// super_cpx
+
+  [] { // Interfaces
+  } // Interfaces
+
+  [] { // fields
+  } // fields
+
+  [] { // methods
+  } // methods
+
+  [] { // Attributes
+    Attr(#7) { // Module
+      [] { // requires
+        #5 0x8020;
+      } // requires
+
+      [] { // exports
+        #6
+        [] { // to
+        }; // end to
+      } // exports
+
+      [] { // uses
+      } // uses
+
+      [] { // provides
+      } // provides
+
+    } // end Module
+    ;
+    Attr(#8) { // Version
+      0x0009;
+    } // end Version
+  } // Attributes
+} // end module mod