changeset 2799:2dc86bb9736a

8052070: javac crashes when there are duplicated type parameters Summary: Avoid eager completion of ClassSymbol while type parameters are being processed. Reviewed-by: jlahoda, mcimadamore Contributed-by: srikanth.adayapalam@oracle.com
author jlahoda
date Tue, 20 Jan 2015 09:51:17 +0100
parents c31aefdd3ab4
children 1b58b3cc63bc
files src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java test/tools/javac/8052070/DuplicateTypeParameter.java test/tools/javac/8052070/DuplicateTypeParameter.out
diffstat 3 files changed, 24 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java	Mon Jan 19 18:29:45 2015 +0000
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java	Tue Jan 20 09:51:17 2015 +0100
@@ -385,7 +385,7 @@
         typeEnvs.put(c, localEnv);
 
         // Fill out class fields.
-        c.completer = typeEnter;
+        c.completer = null; // do not allow the initial completer linger on.
         c.flags_field = chk.checkFlags(tree.pos(), tree.mods.flags, c, tree);
         c.sourcefile = env.toplevel.sourcefile;
         c.members_field = WriteableScope.create(c);
@@ -409,6 +409,9 @@
         // Enter type parameters.
         ct.typarams_field = classEnter(tree.typarams, localEnv);
 
+        // install further completer for this type.
+        c.completer = typeEnter;
+
         // Add non-local class to uncompleted, to make sure it will be
         // completed later.
         if (!c.isLocal() && uncompleted != null) uncompleted.append(c);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/8052070/DuplicateTypeParameter.java	Tue Jan 20 09:51:17 2015 +0100
@@ -0,0 +1,15 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8052070
+ * @summary javac crashes when there are duplicated type parameters
+ * @compile/fail/ref=DuplicateTypeParameter.out -XDrawDiagnostics DuplicateTypeParameter.java
+ */
+
+public class DuplicateTypeParameter<T, T, A> {
+    class Inner <P, P, Q> {}
+    public void foo() {
+        class Local <M, M, N> {};
+    }
+}
+
+class Secondary<D, D, E> {}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/8052070/DuplicateTypeParameter.out	Tue Jan 20 09:51:17 2015 +0100
@@ -0,0 +1,5 @@
+DuplicateTypeParameter.java:8:40: compiler.err.already.defined: kindname.type.variable, T, kindname.class, DuplicateTypeParameter
+DuplicateTypeParameter.java:9:21: compiler.err.already.defined: kindname.type.variable, P, kindname.class, DuplicateTypeParameter.Inner
+DuplicateTypeParameter.java:15:20: compiler.err.already.defined: kindname.type.variable, D, kindname.class, Secondary
+DuplicateTypeParameter.java:11:25: compiler.err.already.defined: kindname.type.variable, M, kindname.class, Local
+4 errors