diff -r 7ceaee0e497b -r 63ef1e0410d1 src/share/classes/com/sun/tools/javac/code/Types.java --- a/src/share/classes/com/sun/tools/javac/code/Types.java Thu May 29 10:48:00 2014 +0200 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java Tue Jun 10 10:22:26 2014 +0100 @@ -1221,14 +1221,35 @@ TypeRelation isSameTypeLoose = new LooseSameTypeVisitor(); private class LooseSameTypeVisitor extends SameTypeVisitor { + + /** cache of the type-variable pairs being (recursively) tested. */ + private Set cache = new HashSet<>(); + @Override boolean sameTypeVars(TypeVar tv1, TypeVar tv2) { - return tv1.tsym == tv2.tsym && visit(tv1.getUpperBound(), tv2.getUpperBound()); + return tv1.tsym == tv2.tsym && checkSameBounds(tv1, tv2); } @Override protected boolean containsTypes(List ts1, List ts2) { return containsTypeEquivalent(ts1, ts2); } + + /** + * Since type-variable bounds can be recursive, we need to protect against + * infinite loops - where the same bounds are checked over and over recursively. + */ + private boolean checkSameBounds(TypeVar tv1, TypeVar tv2) { + TypePair p = new TypePair(tv1, tv2, true); + if (cache.add(p)) { + try { + return visit(tv1.getUpperBound(), tv2.getUpperBound()); + } finally { + cache.remove(p); + } + } else { + return false; + } + } }; /** @@ -3376,9 +3397,16 @@ class TypePair { final Type t1; final Type t2; + boolean strict; + TypePair(Type t1, Type t2) { + this(t1, t2, false); + } + + TypePair(Type t1, Type t2, boolean strict) { this.t1 = t1; this.t2 = t2; + this.strict = strict; } @Override public int hashCode() { @@ -3389,8 +3417,8 @@ if (!(obj instanceof TypePair)) return false; TypePair typePair = (TypePair)obj; - return isSameType(t1, typePair.t1) - && isSameType(t2, typePair.t2); + return isSameType(t1, typePair.t1, strict) + && isSameType(t2, typePair.t2, strict); } } Set mergeCache = new HashSet();