6677785: REGRESSION: StackOverFlowError with Cyclic Class level Type Parameters when used in constructors

Fri, 30 May 2008 11:08:40 +0100

author
mcimadamore
date
Fri, 30 May 2008 11:08:40 +0100
changeset 42
f7e64b33d5a4
parent 41
6e9a43815df7
child 43
fc780e96a16a
child 46
7708bd6d800d

6677785: REGRESSION: StackOverFlowError with Cyclic Class level Type Parameters when used in constructors
Summary: This regression has been caused by previous fix of 6660289
Reviewed-by: jjg

src/share/classes/com/sun/tools/javac/comp/Attr.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/comp/Check.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/6677785/T6677785.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/6677785/T6677785.out file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Fri May 30 10:42:43 2008 +0100
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Fri May 30 11:08:40 2008 +0100
     1.3 @@ -454,6 +454,8 @@
     1.4      void attribTypeVariables(List<JCTypeParameter> typarams, Env<AttrContext> env) {
     1.5          for (JCTypeParameter tvar : typarams) {
     1.6              TypeVar a = (TypeVar)tvar.type;
     1.7 +            a.tsym.flags_field |= UNATTRIBUTED;
     1.8 +            a.bound = Type.noType;
     1.9              if (!tvar.bounds.isEmpty()) {
    1.10                  List<Type> bounds = List.of(attribType(tvar.bounds.head, env));
    1.11                  for (JCExpression bound : tvar.bounds.tail)
    1.12 @@ -464,13 +466,14 @@
    1.13                  // java.lang.Object.
    1.14                  types.setBounds(a, List.of(syms.objectType));
    1.15              }
    1.16 +            a.tsym.flags_field &= ~UNATTRIBUTED;
    1.17          }
    1.18 -    }
    1.19 -
    1.20 -    void attribBounds(List<JCTypeParameter> typarams, Env<AttrContext> env) {
    1.21          for (JCTypeParameter tvar : typarams)
    1.22              chk.checkNonCyclic(tvar.pos(), (TypeVar)tvar.type);
    1.23          attribStats(typarams, env);
    1.24 +    }
    1.25 +
    1.26 +    void attribBounds(List<JCTypeParameter> typarams) {
    1.27          for (JCTypeParameter typaram : typarams) {
    1.28              Type bound = typaram.type.getUpperBound();
    1.29              if (bound != null && bound.tsym instanceof ClassSymbol) {
    1.30 @@ -581,7 +584,7 @@
    1.31          try {
    1.32              chk.checkDeprecatedAnnotation(tree.pos(), m);
    1.33  
    1.34 -            attribBounds(tree.typarams, env);
    1.35 +            attribBounds(tree.typarams);
    1.36  
    1.37              // If we override any other methods, check that we do so properly.
    1.38              // JLS ???
    1.39 @@ -2689,7 +2692,7 @@
    1.40          chk.validateAnnotations(tree.mods.annotations, c);
    1.41  
    1.42          // Validate type parameters, supertype and interfaces.
    1.43 -        attribBounds(tree.typarams, env);
    1.44 +        attribBounds(tree.typarams);
    1.45          chk.validateTypeParams(tree.typarams);
    1.46          chk.validate(tree.extending);
    1.47          chk.validate(tree.implementing);
     2.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java	Fri May 30 10:42:43 2008 +0100
     2.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java	Fri May 30 11:08:40 2008 +0100
     2.3 @@ -1486,6 +1486,8 @@
     2.4  
     2.5      private void checkNonCyclic1(DiagnosticPosition pos, Type t, Set<TypeVar> seen) {
     2.6          final TypeVar tv;
     2.7 +        if  (t.tag == TYPEVAR && (t.tsym.flags() & UNATTRIBUTED) != 0)
     2.8 +            return;
     2.9          if (seen.contains(t)) {
    2.10              tv = (TypeVar)t;
    2.11              tv.bound = new ErrorType();
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/tools/javac/generics/6677785/T6677785.java	Fri May 30 11:08:40 2008 +0100
     3.3 @@ -0,0 +1,35 @@
     3.4 +/*
     3.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
     3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.7 + *
     3.8 + * This code is free software; you can redistribute it and/or modify it
     3.9 + * under the terms of the GNU General Public License version 2 only, as
    3.10 + * published by the Free Software Foundation.
    3.11 + *
    3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    3.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    3.15 + * version 2 for more details (a copy is included in the LICENSE file that
    3.16 + * accompanied this code).
    3.17 + *
    3.18 + * You should have received a copy of the GNU General Public License version
    3.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    3.21 + *
    3.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    3.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    3.24 + * have any questions.
    3.25 + */
    3.26 +
    3.27 +/*
    3.28 + * @test
    3.29 + * @bug     6677785
    3.30 + * @summary REGRESSION: StackOverFlowError with Cyclic Class level Type Parameters when used in constructors
    3.31 + * @author Maurizio Cimadamore
    3.32 + * @compile/fail/ref=T6677785.out -XDstdout -XDrawDiagnostics T6677785.java
    3.33 + */
    3.34 +public class T6677785<E extends T, T extends E> {
    3.35 +     T6677785() {}
    3.36 +     T6677785(E e) {}
    3.37 +     T6677785(E e, T t) {}
    3.38 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/tools/javac/generics/6677785/T6677785.out	Fri May 30 11:08:40 2008 +0100
     4.3 @@ -0,0 +1,2 @@
     4.4 +T6677785.java:31:23: compiler.err.cyclic.inheritance: E
     4.5 +1 error

mercurial