Skip to content

Commit 67baa79

Browse files
committed
Avoid duplicate calls in ReferenceBinding::superInterfaces eclipse-jdt#3601
- Make the method final - Add new recursive method ReferenceBinding.superInterfacesRecursive that takes an IndentityHashMap to keep the visited types Fixes eclipse-jdt#3601
1 parent 5a22a10 commit 67baa79

10 files changed

+35
-23
lines changed

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1438,7 +1438,7 @@ public ReferenceBinding superclass() {
14381438
return LambdaExpression.this.scope.getJavaLangObject();
14391439
}
14401440
@Override
1441-
public ReferenceBinding[] superInterfaces() {
1441+
protected ReferenceBinding[] superInterfacesRecursive(Map<ReferenceBinding, Object> visited) {
14421442
return new ReferenceBinding[] { (ReferenceBinding) LambdaExpression.this.resolvedType };
14431443
}
14441444
@Override

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -2524,10 +2524,12 @@ private void detectCircularHierarchy() {
25242524

25252525
// NOTE: superInterfaces of binary types are resolved when needed
25262526
@Override
2527-
public ReferenceBinding[] superInterfaces() {
2528-
2527+
protected ReferenceBinding[] superInterfacesRecursive(Map<ReferenceBinding, Object> visited) {
2528+
if (visited.put(this, this) != null) { // do not evaluate the same type twice
2529+
return this.superInterfaces;
2530+
}
25292531
if (!isPrototype()) {
2530-
return this.superInterfaces = this.prototype.superInterfaces();
2532+
return this.superInterfaces = this.prototype.superInterfacesRecursive(visited); // TODO (visjee) protect from duplicated calls
25312533
}
25322534
if ((this.tagBits & TagBits.HasUnresolvedSuperinterfaces) == 0)
25332535
return this.superInterfaces;
@@ -2541,15 +2543,15 @@ public ReferenceBinding[] superInterfaces() {
25412543
boolean wasToleratingMissingTypeProcessingAnnotations = this.environment.mayTolerateMissingType;
25422544
this.environment.mayTolerateMissingType = true; // https://bugs.eclipse.org/bugs/show_bug.cgi?id=360164
25432545
try {
2544-
this.superInterfaces[i].superclass();
2546+
this.superInterfaces[i].superclass(); // TODO (visjee) do I need to prevent duplicated calls here too? Probably NOT.
25452547
if (this.superInterfaces[i].isParameterizedType()) {
25462548
ReferenceBinding superType = this.superInterfaces[i].actualType();
25472549
if (TypeBinding.equalsEquals(superType, this)) {
25482550
this.tagBits |= TagBits.HierarchyHasProblems;
25492551
continue;
25502552
}
25512553
}
2552-
this.superInterfaces[i].superInterfaces();
2554+
this.superInterfaces[i].superInterfacesRecursive(visited); // TODO (visjee) protect from duplicated calls
25532555
} finally {
25542556
this.environment.mayTolerateMissingType = wasToleratingMissingTypeProcessingAnnotations;
25552557
}

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/InferenceVariable.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ void collectInferenceVariables(Set<InferenceVariable> variables) {
174174
}
175175

176176
@Override
177-
public ReferenceBinding[] superInterfaces() {
177+
protected ReferenceBinding[] superInterfacesRecursive(Map<ReferenceBinding, Object> visited) {
178178
return Binding.NO_SUPERINTERFACES;
179179
}
180180

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/IntersectionTypeBinding18.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
package org.eclipse.jdt.internal.compiler.lookup;
2525

26+
import java.util.Map;
2627
import java.util.Set;
2728
import org.eclipse.jdt.internal.compiler.ast.Wildcard;
2829
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
@@ -153,7 +154,7 @@ public ReferenceBinding superclass() {
153154
}
154155

155156
@Override
156-
public ReferenceBinding [] superInterfaces() {
157+
protected ReferenceBinding[] superInterfacesRecursive(Map<ReferenceBinding, Object> visited) {
157158
if (this.intersectingTypes[0].isClass()) {
158159
ReferenceBinding [] superInterfaces = new ReferenceBinding[this.length - 1];
159160
System.arraycopy(this.intersectingTypes, 1, superInterfaces, 0, this.length - 1);

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ParameterizedTypeBinding.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -1551,11 +1551,12 @@ public ReferenceBinding superclass() {
15511551
* @see org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding#superInterfaces()
15521552
*/
15531553
@Override
1554-
public ReferenceBinding[] superInterfaces() {
1555-
if (this.superInterfaces == null) {
1554+
protected ReferenceBinding[] superInterfacesRecursive(Map<ReferenceBinding, Object> visited) {
1555+
// TODO (visjee) protect from duplicated calls
1556+
if (this.superInterfaces == null && visited.put(this, this) == null) {
15561557
if (this.type.isHierarchyBeingConnected())
15571558
return Binding.NO_SUPERINTERFACES; // prevent superinterfaces from being assigned before they are connected
1558-
this.superInterfaces = Scope.substitute(this, this.type.superInterfaces());
1559+
this.superInterfaces = Scope.substitute(this, this.type.superInterfacesRecursive(visited));
15591560
if (this.superInterfaces != null) {
15601561
for (int i = this.superInterfaces.length; --i >= 0;) {
15611562
this.typeBits |= (this.superInterfaces[i].typeBits & TypeIds.InheritableBits);

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ProblemReferenceBinding.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package org.eclipse.jdt.internal.compiler.lookup;
1616

1717
import java.lang.reflect.Field;
18+
import java.util.Map;
1819
import org.eclipse.jdt.core.compiler.CharOperation;
1920

2021
@SuppressWarnings("rawtypes")
@@ -60,10 +61,10 @@ public ReferenceBinding superclass() {
6061
}
6162

6263
@Override
63-
public ReferenceBinding[] superInterfaces() {
64+
protected ReferenceBinding[] superInterfacesRecursive(Map<ReferenceBinding, Object> visited) {
6465
if (this.closestMatch != null)
65-
return this.closestMatch.superInterfaces();
66-
return super.superInterfaces();
66+
return this.closestMatch.superInterfacesRecursive(visited); // TODO (visjee) protect from duplicated calls
67+
return super.superInterfacesRecursive(visited);
6768
}
6869

6970
@Override

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import java.util.Comparator;
5858
import java.util.HashMap;
5959
import java.util.HashSet;
60+
import java.util.IdentityHashMap;
6061
import java.util.List;
6162
import java.util.Map;
6263
import java.util.Set;
@@ -2098,7 +2099,11 @@ public ReferenceBinding superclass() {
20982099
}
20992100

21002101
@Override
2101-
public ReferenceBinding[] superInterfaces() {
2102+
public final ReferenceBinding[] superInterfaces() {
2103+
return superInterfacesRecursive(new IdentityHashMap<>());
2104+
}
2105+
2106+
protected ReferenceBinding[] superInterfacesRecursive(Map<ReferenceBinding, Object> visited) {
21022107
return Binding.NO_SUPERINTERFACES;
21032108
}
21042109

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -3178,9 +3178,9 @@ public ReferenceBinding superclass() {
31783178
}
31793179

31803180
@Override
3181-
public ReferenceBinding[] superInterfaces() {
3182-
if (!isPrototype())
3183-
return this.superInterfaces = this.prototype.superInterfaces();
3181+
protected ReferenceBinding[] superInterfacesRecursive(Map<ReferenceBinding, Object> visited) {
3182+
if (!isPrototype() && visited.put(this, this) == null)
3183+
return this.superInterfaces = this.prototype.superInterfacesRecursive(visited); // TODO (visjee) protect from duplicated calls
31843184
return this.superInterfaces != null ? this.superInterfaces : isAnnotationType() ? this.superInterfaces = new ReferenceBinding [] { this.scope.getJavaLangAnnotationAnnotation() } : null;
31853185
}
31863186

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/TypeVariableBinding.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,17 @@
4545
import java.util.Arrays;
4646
import java.util.HashSet;
4747
import java.util.List;
48+
import java.util.Map;
4849
import java.util.Set;
4950
import java.util.function.Consumer;
5051
import org.eclipse.jdt.core.compiler.CharOperation;
5152
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
5253
import org.eclipse.jdt.internal.compiler.ast.Annotation;
5354
import org.eclipse.jdt.internal.compiler.ast.NullAnnotationMatching;
55+
import org.eclipse.jdt.internal.compiler.ast.NullAnnotationMatching.CheckMode;
5456
import org.eclipse.jdt.internal.compiler.ast.TypeParameter;
5557
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
5658
import org.eclipse.jdt.internal.compiler.ast.Wildcard;
57-
import org.eclipse.jdt.internal.compiler.ast.NullAnnotationMatching.CheckMode;
5859
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
5960
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
6061
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants.BoundCheckStatus;
@@ -935,7 +936,7 @@ public ReferenceBinding superclass() {
935936
}
936937

937938
@Override
938-
public ReferenceBinding[] superInterfaces() {
939+
protected ReferenceBinding[] superInterfacesRecursive(Map<ReferenceBinding, Object> visited) {
939940
return this.superInterfaces;
940941
}
941942

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/WildcardBinding.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
package org.eclipse.jdt.internal.compiler.lookup;
2929

3030
import java.util.List;
31+
import java.util.Map;
3132
import java.util.Set;
3233
import org.eclipse.jdt.core.compiler.CharOperation;
3334
import org.eclipse.jdt.internal.compiler.ast.Annotation;
@@ -927,10 +928,10 @@ public ReferenceBinding superclass() {
927928
}
928929

929930
@Override
930-
public ReferenceBinding[] superInterfaces() {
931-
if (this.superInterfaces == null) {
931+
protected ReferenceBinding[] superInterfacesRecursive(Map<ReferenceBinding, Object> visited) {
932+
if (this.superInterfaces == null && visited.put(this, this) == null) {
932933
if (typeVariable() != null) {
933-
this.superInterfaces = this.typeVariable.superInterfaces();
934+
this.superInterfaces = this.typeVariable.superInterfacesRecursive(visited);// TODO (visjee) protect from duplicated calls
934935
} else {
935936
this.superInterfaces = Binding.NO_SUPERINTERFACES;
936937
}

0 commit comments

Comments
 (0)