From cfdd5c9a8996745b65666bee094db9fbef470246 Mon Sep 17 00:00:00 2001 From: Suzanne Millstein Date: Fri, 18 Oct 2024 15:45:40 -0700 Subject: [PATCH] Expect crash due to javac bug --- .../framework/type/DefaultTypeHierarchy.java | 15 ++++++++++++++- framework/tests/all-systems/Issue6867.java | 12 ++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 framework/tests/all-systems/Issue6867.java diff --git a/framework/src/main/java/org/checkerframework/framework/type/DefaultTypeHierarchy.java b/framework/src/main/java/org/checkerframework/framework/type/DefaultTypeHierarchy.java index 92b8deb9b82..48dc6c13aae 100644 --- a/framework/src/main/java/org/checkerframework/framework/type/DefaultTypeHierarchy.java +++ b/framework/src/main/java/org/checkerframework/framework/type/DefaultTypeHierarchy.java @@ -412,7 +412,20 @@ protected boolean isContainedBy( if (canBeCovariant) { return isSubtype(inside, outside, currentTop); } - return areEqualInHierarchy(inside, outside); + + try { + return areEqualInHierarchy(inside, outside); + } catch (Exception e) { + // Ignore exception and try capturing. + // See https://github.com/typetools/checker-framework/issues/6867. + // https://bugs.openjdk.org/browse/JDK-8054309 + } + AnnotatedTypeMirror capturedOutside = outside.atypeFactory.applyCaptureConversion(outside); + previousResult = areEqualVisitHistory.get(inside, capturedOutside, currentTop); + if (previousResult != null) { + return previousResult; + } + return areEqualInHierarchy(inside, capturedOutside); } /** diff --git a/framework/tests/all-systems/Issue6867.java b/framework/tests/all-systems/Issue6867.java new file mode 100644 index 00000000000..4bff02c24c7 --- /dev/null +++ b/framework/tests/all-systems/Issue6867.java @@ -0,0 +1,12 @@ +public class Issue6867 { + interface A {} + + static class B> {} + + void main(B> b) { + @SuppressWarnings("super.wildcard") // This is a true positive. + // This code is rejected by Eclipse and IntelliJ's presentation compiler. It's a bug in javac. + // https://bugs.openjdk.org/browse/JDK-8054309 + B> x = b; + } +}