From 8e99d2ef8f99c9d9c86b33f7e4751a4cf0b32657 Mon Sep 17 00:00:00 2001 From: Suzanne Millstein Date: Mon, 9 Aug 2021 09:32:17 -0700 Subject: [PATCH 1/2] Fix issue. --- .../framework/type/AnnotatedTypeFactory.java | 7 +++++-- framework/tests/all-systems/Issue4852.java | 10 ++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 framework/tests/all-systems/Issue4852.java 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 4471cee719e..76e38eef8ef 100644 --- a/framework/src/main/java/org/checkerframework/framework/type/AnnotatedTypeFactory.java +++ b/framework/src/main/java/org/checkerframework/framework/type/AnnotatedTypeFactory.java @@ -4998,7 +4998,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 @@ -5007,7 +5008,9 @@ 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) { + first = candidate; boolean doesNotContain = true; for (AnnotatedTypeVariable other : collection) { if (candidate != other && captureScanner.visit(candidate, other.getUnderlyingType())) { @@ -5019,7 +5022,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) {} + } +} From 1a51dac7e6e050c6db7dcfb56248035f2f1160a8 Mon Sep 17 00:00:00 2001 From: Suzanne Millstein Date: Thu, 12 Aug 2021 11:21:39 -0700 Subject: [PATCH 2/2] Fix. --- .../checkerframework/framework/type/AnnotatedTypeFactory.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 6596d64323e..3285d2af876 100644 --- a/framework/src/main/java/org/checkerframework/framework/type/AnnotatedTypeFactory.java +++ b/framework/src/main/java/org/checkerframework/framework/type/AnnotatedTypeFactory.java @@ -5004,7 +5004,9 @@ private AnnotatedTypeVariable doesNotContainOthers( Collection collection) { AnnotatedTypeVariable first = null; for (AnnotatedTypeVariable candidate : collection) { - first = candidate; + if (first == null) { + first = candidate; + } boolean doesNotContain = true; for (AnnotatedTypeVariable other : collection) { if (candidate != other && captureScanner.visit(candidate, other.getUnderlyingType())) {