From d999c1d3dd338e7ea9d9cf9aa93ca5f837e431cb Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Wed, 2 Nov 2022 11:57:42 +0000 Subject: [PATCH 1/2] Java: Add test for multiply-bounded wildcards This exercises several cases of variables bounded both by a wildcard and by a bound on the type parameter, checking that the extractor strips the wildcards and captures to decide on a concrete type for the parameters and return values. --- .../multiply-bounded-wildcards/Test.java | 19 +++++++++++++++++++ .../multiply-bounded-wildcards/test.expected | 4 ++++ .../multiply-bounded-wildcards/test.ql | 5 +++++ 3 files changed, 28 insertions(+) create mode 100644 java/ql/test/library-tests/multiply-bounded-wildcards/Test.java create mode 100644 java/ql/test/library-tests/multiply-bounded-wildcards/test.expected create mode 100644 java/ql/test/library-tests/multiply-bounded-wildcards/test.ql diff --git a/java/ql/test/library-tests/multiply-bounded-wildcards/Test.java b/java/ql/test/library-tests/multiply-bounded-wildcards/Test.java new file mode 100644 index 00000000000..69e35b45b39 --- /dev/null +++ b/java/ql/test/library-tests/multiply-bounded-wildcards/Test.java @@ -0,0 +1,19 @@ +public class Test { + + static class BoundedGeneric { + public T getter(int unused) { return null; } + public void setter(T t) { } + } + + public static BoundedGeneric getUnbounded() { return null; } + + public static BoundedGeneric getLowerBounded() { return null; } + + public static void test() { + CharSequence cs = getUnbounded().getter(0); + Object o = getLowerBounded().getter(0); + getUnbounded().setter(null); + getLowerBounded().setter(null); + } + +} diff --git a/java/ql/test/library-tests/multiply-bounded-wildcards/test.expected b/java/ql/test/library-tests/multiply-bounded-wildcards/test.expected new file mode 100644 index 00000000000..ce09da85f2d --- /dev/null +++ b/java/ql/test/library-tests/multiply-bounded-wildcards/test.expected @@ -0,0 +1,4 @@ +| Test$BoundedGeneric.class:0:0:0:0 | getter | Test$BoundedGeneric.class:0:0:0:0 | BoundedGeneric | CharSequence | int | +| Test$BoundedGeneric.class:0:0:0:0 | getter | Test$BoundedGeneric.class:0:0:0:0 | BoundedGeneric | CharSequence | int | +| Test$BoundedGeneric.class:0:0:0:0 | setter | Test$BoundedGeneric.class:0:0:0:0 | BoundedGeneric | void | String | +| Test$BoundedGeneric.class:0:0:0:0 | setter | Test$BoundedGeneric.class:0:0:0:0 | BoundedGeneric | void | | diff --git a/java/ql/test/library-tests/multiply-bounded-wildcards/test.ql b/java/ql/test/library-tests/multiply-bounded-wildcards/test.ql new file mode 100644 index 00000000000..16ec4617e0a --- /dev/null +++ b/java/ql/test/library-tests/multiply-bounded-wildcards/test.ql @@ -0,0 +1,5 @@ +import java + +from MethodAccess ma +select ma.getCallee(), ma.getCallee().getDeclaringType(), ma.getCallee().getReturnType().toString(), + ma.getCallee().getAParamType().toString() From e877967a6296a7ba2852d317e47d80adb07dfc29 Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Fri, 4 Nov 2022 13:46:01 +0000 Subject: [PATCH 2/2] Add test verifying no malformed wildcards result from captured type variables with a Collection type --- .../wildcards-and-captured-types/Test.java | 13 +++++++++++++ .../wildcards-and-captured-types/test.expected | 0 .../wildcards-and-captured-types/test.ql | 5 +++++ 3 files changed, 18 insertions(+) create mode 100644 java/ql/test/library-tests/wildcards-and-captured-types/Test.java create mode 100644 java/ql/test/library-tests/wildcards-and-captured-types/test.expected create mode 100644 java/ql/test/library-tests/wildcards-and-captured-types/test.ql diff --git a/java/ql/test/library-tests/wildcards-and-captured-types/Test.java b/java/ql/test/library-tests/wildcards-and-captured-types/Test.java new file mode 100644 index 00000000000..1696a035fd6 --- /dev/null +++ b/java/ql/test/library-tests/wildcards-and-captured-types/Test.java @@ -0,0 +1,13 @@ +import java.util.Collection; + +public class Test { + + public Collection getCollection() { + return null; + } + + public void test() { + this.getCollection().isEmpty(); + } + +} diff --git a/java/ql/test/library-tests/wildcards-and-captured-types/test.expected b/java/ql/test/library-tests/wildcards-and-captured-types/test.expected new file mode 100644 index 00000000000..e69de29bb2d diff --git a/java/ql/test/library-tests/wildcards-and-captured-types/test.ql b/java/ql/test/library-tests/wildcards-and-captured-types/test.ql new file mode 100644 index 00000000000..3e28a2c1d67 --- /dev/null +++ b/java/ql/test/library-tests/wildcards-and-captured-types/test.ql @@ -0,0 +1,5 @@ +import java + +from Method m, Type t +where m.getAParamType() = t and t.toString().matches("%? super ? extends%") +select m, t