From da864aeccd0f19c4494eabbca8610cf26075a2a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sat, 24 Aug 2024 16:48:03 +0200 Subject: [PATCH 1/2] Fix #5167 - issue with type projection --- .../pmd/lang/java/types/TypeOps.java | 7 ++++ .../pmd/lang/java/types/TypeOpsTest.kt | 37 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/TypeOps.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/TypeOps.java index 051ea91c027..a6ac8828196 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/TypeOps.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/TypeOps.java @@ -1170,6 +1170,13 @@ public JTypeMirror visitClass(JClassType t, RecursionStop recursionStop) { } else if (!upwards) { // If Ai is a type that mentions a restricted type variable, then Ai' is undefined. return NO_DOWN_PROJECTION; + } else if (u instanceof JWildcardType) { + // The rest of this function, below, treats u as the bound of a wildcard, + // but if u is already a wildcard (and therefore ai was a wildcard), we + // are already done. + newTargs.add(u); + change = true; + continue; } change = true; diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/TypeOpsTest.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/TypeOpsTest.kt index 55a1b19a82b..421a778c4a0 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/TypeOpsTest.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/TypeOpsTest.kt @@ -95,7 +95,44 @@ class TypeOpsTest : FunSpec({ } + test("#5167 problem in projection") { + val (acu, spy) = javaParser.parseWithTypeInferenceSpy( + """ +import java.lang.annotation.Annotation; +interface Bar { + Baz getBaz(); +} + +interface Predicate { + boolean check(T t); +} +interface Stream{ + T findSome(); +} +interface Baz{ + Stream> filterMethods(Predicate p); +} + +class Foo { + + private static Bar foo( + Bar type, Class annotation, boolean required) { + var method = type.getBaz().filterMethods(m -> true).findSome(); + return method; + } +} + """.trimIndent() + ) + + val (barT) = acu.declaredTypeSignatures() + val methodId = acu.varId("method") + + spy.shouldBeOk { + methodId shouldHaveType barT[`?`] + } + } } } + }) From be47aab26543d40c31a9713df4baf60abf0bb1db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Mart=C3=ADn=20Sotuyo=20Dodero?= Date: Sat, 24 Aug 2024 18:18:38 -0300 Subject: [PATCH 2/2] Update changelog, refs #5167 --- docs/pages/release_notes.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index c12e6be8405..1bc6f6fc002 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -17,7 +17,9 @@ This is a {{ site.pmd.release_type }} release. ### 🐛 Fixed Issues * apex-performance * [#5139](https://github.com/pmd/pmd/issues/5139): \[apex] OperationWithHighCostInLoop not firing in triggers -* pmd-bestpractices +* java + * [#5167](https://github.com/pmd/pmd/pull/5167): \[java] java.lang.IllegalArgumentException: \<\?\> cannot be a wildcard bound +* java-bestpractices * [#5145](https://github.com/pmd/pmd/issues/5145): \[java] False positive UnusedPrivateMethod * plsql-bestpractices * [#5132](https://github.com/pmd/pmd/issues/5132): \[plsql] TomKytesDespair - exception for more complex exception handler