8078473: javac diamond finder crashes when used to build java.base module.
authorsadayapalam
Mon, 27 Apr 2015 17:36:20 +0530
changeset 30404 952a476681b2
parent 30403 c904bbdc5ec1
child 30405 3da6595b205f
8078473: javac diamond finder crashes when used to build java.base module. Reviewed-by: mcimadamore
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Analyzer.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeMaker.java
langtools/test/tools/javac/generics/diamond/6939780/T6939780_9.out
langtools/test/tools/javac/generics/diamond/neg/T8078473.java
langtools/test/tools/javac/generics/diamond/neg/T8078473.out
langtools/test/tools/javac/generics/diamond/neg/T8078473_2.java
langtools/test/tools/javac/generics/diamond/neg/T8078473_2.out
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Analyzer.java	Sat Apr 25 15:59:54 2015 +0530
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Analyzer.java	Mon Apr 27 17:36:20 2015 +0530
@@ -226,8 +226,18 @@
         @Override
         void process(JCNewClass oldTree, JCNewClass newTree, boolean hasErrors) {
             if (!hasErrors) {
-                List<Type> inferredArgs = newTree.type.getTypeArguments();
-                List<Type> explicitArgs = oldTree.type.getTypeArguments();
+                List<Type> inferredArgs, explicitArgs;
+                if (oldTree.def != null) {
+                    inferredArgs = newTree.def.implementing.nonEmpty()
+                                      ? newTree.def.implementing.get(0).type.getTypeArguments()
+                                      : newTree.def.extending.type.getTypeArguments();
+                    explicitArgs = oldTree.def.implementing.nonEmpty()
+                                      ? oldTree.def.implementing.get(0).type.getTypeArguments()
+                                      : oldTree.def.extending.type.getTypeArguments();
+                } else {
+                    inferredArgs = newTree.type.getTypeArguments();
+                    explicitArgs = oldTree.type.getTypeArguments();
+                }
                 for (Type t : inferredArgs) {
                     if (!types.isSameType(t, explicitArgs.head)) {
                         log.warning(oldTree.clazz, "diamond.redundant.args.1",
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java	Sat Apr 25 15:59:54 2015 +0530
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java	Mon Apr 27 17:36:20 2015 +0530
@@ -2006,6 +2006,8 @@
      *  @param name      The type's name.
      */
     Symbol findType(Env<AttrContext> env, Name name) {
+        if (name == names.empty)
+            return typeNotFound; // do not allow inadvertent "lookup" of anonymous types
         Symbol bestSoFar = typeNotFound;
         Symbol sym;
         boolean staticOnly = false;
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeMaker.java	Sat Apr 25 15:59:54 2015 +0530
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeMaker.java	Mon Apr 27 17:36:20 2015 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -690,7 +690,7 @@
             break;
         case WILDCARD: {
             WildcardType a = ((WildcardType) t);
-            tp = Wildcard(TypeBoundKind(a.kind), Type(a.type));
+            tp = Wildcard(TypeBoundKind(a.kind), a.kind == BoundKind.UNBOUND ? null : Type(a.type));
             break;
         }
         case CLASS:
--- a/langtools/test/tools/javac/generics/diamond/6939780/T6939780_9.out	Sat Apr 25 15:59:54 2015 +0530
+++ b/langtools/test/tools/javac/generics/diamond/6939780/T6939780_9.out	Mon Apr 27 17:36:20 2015 +0530
@@ -3,11 +3,11 @@
 T6939780.java:23:28: compiler.warn.diamond.redundant.args.1: T6939780.Foo<java.lang.Integer>, T6939780.Foo<java.lang.Number>
 T6939780.java:24:33: compiler.warn.diamond.redundant.args
 T6939780.java:25:28: compiler.warn.diamond.redundant.args
-T6939780.java:26:28: compiler.warn.diamond.redundant.args
+T6939780.java:26:28: compiler.warn.diamond.redundant.args.1: T6939780.Foo<java.lang.Integer>, T6939780.Foo<java.lang.Number>
 T6939780.java:30:19: compiler.warn.diamond.redundant.args
 T6939780.java:31:19: compiler.warn.diamond.redundant.args
 T6939780.java:32:19: compiler.warn.diamond.redundant.args.1: T6939780.Foo<java.lang.Integer>, T6939780.Foo<java.lang.Number>
 T6939780.java:33:19: compiler.warn.diamond.redundant.args
 T6939780.java:34:19: compiler.warn.diamond.redundant.args
-T6939780.java:35:19: compiler.warn.diamond.redundant.args
+T6939780.java:35:19: compiler.warn.diamond.redundant.args.1: T6939780.Foo<java.lang.Integer>, T6939780.Foo<java.lang.Number>
 12 warnings
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/generics/diamond/neg/T8078473.java	Mon Apr 27 17:36:20 2015 +0530
@@ -0,0 +1,18 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8078473
+ * @summary  javac diamond finder crashes when used to build java.base module
+ * @compile/ref=T8078473.out T8078473.java -XDrawDiagnostics -XDfind=diamond
+ */
+
+class T8078473<P, Q> {
+
+    static class C<T, U> {
+        C(T8078473<?, ?> p) {}
+    }
+
+    {
+        new C<Q, Q>(this) {};
+        new C<Q, Q>(this);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/generics/diamond/neg/T8078473.out	Mon Apr 27 17:36:20 2015 +0530
@@ -0,0 +1,3 @@
+T8078473.java:15:14: compiler.warn.diamond.redundant.args.1: T8078473.C<Q,Q>, T8078473.C<java.lang.Object,java.lang.Object>
+T8078473.java:16:14: compiler.warn.diamond.redundant.args.1: T8078473.C<Q,Q>, T8078473.C<java.lang.Object,java.lang.Object>
+2 warnings
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/generics/diamond/neg/T8078473_2.java	Mon Apr 27 17:36:20 2015 +0530
@@ -0,0 +1,20 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8078473
+ * @summary  javac diamond finder crashes when used to build java.base module
+ * @compile/ref=T8078473_2.out T8078473_2.java -XDrawDiagnostics -XDfind=diamond
+ */
+
+package java.util.stream;
+
+class T8078473_2<P, Q> {
+
+    static class C<T, U> {
+        C(T8078473_2<?, ?> p) {}
+    }
+
+    {
+       new C<Q, Q>(this) {};
+       new C<Q, Q>(this);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/generics/diamond/neg/T8078473_2.out	Mon Apr 27 17:36:20 2015 +0530
@@ -0,0 +1,3 @@
+T8078473_2.java:17:13: compiler.warn.diamond.redundant.args.1: java.util.stream.T8078473_2.C<Q,Q>, java.util.stream.T8078473_2.C<java.lang.Object,java.lang.Object>
+T8078473_2.java:18:13: compiler.warn.diamond.redundant.args.1: java.util.stream.T8078473_2.C<Q,Q>, java.util.stream.T8078473_2.C<java.lang.Object,java.lang.Object>
+2 warnings