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
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java Mon Jan 19 18:29:45 2015 +0000
+++ b/langtools/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/langtools/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/langtools/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