diff --git a/framework/src/main/java/org/checkerframework/framework/type/AnnotatedTypeFactory.java b/framework/src/main/java/org/checkerframework/framework/type/AnnotatedTypeFactory.java index 446cf869264..3285d2af876 100644 --- a/framework/src/main/java/org/checkerframework/framework/type/AnnotatedTypeFactory.java +++ b/framework/src/main/java/org/checkerframework/framework/type/AnnotatedTypeFactory.java @@ -4992,7 +4992,8 @@ public List order(Collection colle /** * Returns the first TypeVariable in {@code collection} that does not lexically contain any other - * type in the collection. + * type in the collection. Or if all the TypeVariables contain another, then it returns the first + * TypeVariable in {@code collection}. * * @param collection a collection of type variables * @return the first TypeVariable in {@code collection} that does not contain any other type in @@ -5001,7 +5002,11 @@ public List order(Collection colle @SuppressWarnings("interning:not.interned") // must be the same object from collection private AnnotatedTypeVariable doesNotContainOthers( Collection collection) { + AnnotatedTypeVariable first = null; for (AnnotatedTypeVariable candidate : collection) { + if (first == null) { + first = candidate; + } boolean doesNotContain = true; for (AnnotatedTypeVariable other : collection) { if (candidate != other && captureScanner.visit(candidate, other.getUnderlyingType())) { @@ -5013,7 +5018,7 @@ private AnnotatedTypeVariable doesNotContainOthers( return candidate; } } - throw new BugInCF("Not found: %s", StringsPlume.join(",", collection)); + return first; } /** diff --git a/framework/tests/all-systems/Issue4852.java b/framework/tests/all-systems/Issue4852.java new file mode 100644 index 00000000000..df423761342 --- /dev/null +++ b/framework/tests/all-systems/Issue4852.java @@ -0,0 +1,10 @@ +@SuppressWarnings("all") // Just check for crashes. +public class Issue4852 { + interface Class1, B extends Class1.Class2> { + abstract class Class2, B extends Class2> {} + } + + class Class3 { + private void f(Class1 x) {} + } +}