changeset 2705:4235749f4989

8062977: Inference: NullPointerException during bound incorporation Summary: Bogus Types.asSuper call on array type symbol Reviewed-by: vromero
author mcimadamore
date Thu, 06 Nov 2014 14:33:22 +0000
parents 7b6a6aeeb544
children 5ff1cd07bd92
files src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java test/tools/javac/generics/inference/8062977/T8062977.java test/tools/javac/generics/inference/8062977/T8062977.out
diffstat 3 files changed, 42 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java	Thu Nov 06 14:31:56 2014 +0000
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java	Thu Nov 06 14:33:22 2014 +0000
@@ -676,13 +676,19 @@
         ListBuffer<Pair<Type, Type>> commonSupertypes = new ListBuffer<>();
         for (Type sup : supertypesToCheck) {
             if (sup.isParameterized()) {
-                Type asSuperOfT = types.asSuper(t, sup.tsym);
-                Type asSuperOfS = types.asSuper(s, sup.tsym);
+                Type asSuperOfT = asSuper(t, sup);
+                Type asSuperOfS = asSuper(s, sup);
                 commonSupertypes.add(new Pair<>(asSuperOfT, asSuperOfS));
             }
         }
         return commonSupertypes.toList();
     }
+    //where
+        private Type asSuper(Type t, Type sup) {
+            return (sup.hasTag(ARRAY)) ?
+                    new ArrayType(asSuper(types.elemtype(t), types.elemtype(sup)), syms.arrayClass) :
+                    types.asSuper(t, sup.tsym);
+        }
 
     /**
      * This enumeration defines an entry point for doing inference variable
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/generics/inference/8062977/T8062977.java	Thu Nov 06 14:33:22 2014 +0000
@@ -0,0 +1,29 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8062977
+ * @summary Inference: NullPointerException during bound incorporation
+ *
+ * @compile/fail/ref=T8062977.out -XDrawDiagnostics T8062977.java
+ */
+
+import java.util.List;
+
+class T8062977 {
+    <T extends B, B> T m(Class<B> cb) { return null; }
+
+    void test1(Class<Iterable<?>> cb) {
+        List<Integer>[] r1 = m(cb); //fail
+        List<Integer> r2 = m(cb); //ok
+    }
+
+    void test2(Class<Iterable<?>[]> cb) {
+        List<Integer>[] r1 = m(cb); //ok
+        List<Integer> r2 = m(cb); //fail
+    }
+
+    void test3(Class<Iterable<?>[][]> cb) {
+        List<Integer>[][] r1 = m(cb); //ok
+        List<Integer>[] r2 = m(cb); //fail
+        List<Integer> r3 = m(cb); //fail
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/generics/inference/8062977/T8062977.out	Thu Nov 06 14:33:22 2014 +0000
@@ -0,0 +1,5 @@
+T8062977.java:15:31: compiler.err.prob.found.req: (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.util.List<java.lang.Integer>[]&java.lang.Iterable<?>, java.util.List<java.lang.Integer>[],java.lang.Iterable<?>,java.lang.Object)
+T8062977.java:21:29: compiler.err.prob.found.req: (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Iterable<?>[]&java.util.List<java.lang.Integer>, java.util.List<java.lang.Integer>,java.lang.Iterable<?>[],java.lang.Object)
+T8062977.java:26:31: compiler.err.prob.found.req: (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.util.List<java.lang.Integer>[], java.util.List<java.lang.Integer>[],java.lang.Iterable<?>[][],java.lang.Object)
+T8062977.java:27:29: compiler.err.prob.found.req: (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Iterable<?>[][]&java.util.List<java.lang.Integer>, java.util.List<java.lang.Integer>,java.lang.Iterable<?>[][],java.lang.Object)
+4 errors