From e352a4b99445b0020c24b89d8df425d84d97c888 Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Mon, 10 Jan 2022 18:19:31 +0000 Subject: [PATCH] Note that parameterizations of local classes are themselves local Previously `LocalClass` itself would match `.isLocal()` whereas `LocalClass` would not. Rather than require each individual user to check for `.getSourceDeclaration().isLocal()`, let's note that the specializations themselves are local. --- java/ql/lib/semmle/code/java/Type.qll | 2 +- java/ql/test/library-tests/localclasses/Test.java | 11 +++++++++++ java/ql/test/library-tests/localclasses/test.expected | 2 ++ java/ql/test/library-tests/localclasses/test.ql | 7 +++++++ 4 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 java/ql/test/library-tests/localclasses/Test.java create mode 100644 java/ql/test/library-tests/localclasses/test.expected create mode 100644 java/ql/test/library-tests/localclasses/test.ql diff --git a/java/ql/lib/semmle/code/java/Type.qll b/java/ql/lib/semmle/code/java/Type.qll index 1755442545d..1d8e0f81e97 100755 --- a/java/ql/lib/semmle/code/java/Type.qll +++ b/java/ql/lib/semmle/code/java/Type.qll @@ -905,7 +905,7 @@ class Interface extends ClassOrInterface, @interface { /** A class or interface. */ class ClassOrInterface extends RefType, @classorinterface { /** Holds if this class or interface is local. */ - predicate isLocal() { isLocalClassOrInterface(this, _) } + predicate isLocal() { isLocalClassOrInterface(this.getSourceDeclaration(), _) } /** Holds if this class or interface is package protected, that is, neither public nor private nor protected. */ predicate isPackageProtected() { diff --git a/java/ql/test/library-tests/localclasses/Test.java b/java/ql/test/library-tests/localclasses/Test.java new file mode 100644 index 00000000000..b1765b48439 --- /dev/null +++ b/java/ql/test/library-tests/localclasses/Test.java @@ -0,0 +1,11 @@ +public class Test { + + public static void method() { + + class GenericLocal { } + + GenericLocal instantiated = new GenericLocal<>(); + + } + +} diff --git a/java/ql/test/library-tests/localclasses/test.expected b/java/ql/test/library-tests/localclasses/test.expected new file mode 100644 index 00000000000..ca17141b224 --- /dev/null +++ b/java/ql/test/library-tests/localclasses/test.expected @@ -0,0 +1,2 @@ +| Test$1GenericLocal.class:0:0:0:0 | GenericLocal | +| Test.java:5:11:5:22 | GenericLocal | diff --git a/java/ql/test/library-tests/localclasses/test.ql b/java/ql/test/library-tests/localclasses/test.ql new file mode 100644 index 00000000000..1120279f1da --- /dev/null +++ b/java/ql/test/library-tests/localclasses/test.ql @@ -0,0 +1,7 @@ +import java + +from ClassOrInterface ci +where + ci.getSourceDeclaration().fromSource() and + ci.isLocal() +select ci