diff --git a/java/ql/automodel/src/AutomodelAlertSinkUtil.qll b/java/ql/automodel/src/AutomodelAlertSinkUtil.qll index ce0305f6095..f20c8e57b6c 100644 --- a/java/ql/automodel/src/AutomodelAlertSinkUtil.qll +++ b/java/ql/automodel/src/AutomodelAlertSinkUtil.qll @@ -99,7 +99,7 @@ class PotentialSinkModelExpr extends Expr { ) and (if argIdx = -1 then input = "Argument[this]" else input = "Argument[" + argIdx + "]") and package = callable.getDeclaringType().getPackage().getName() and - type = callable.getDeclaringType().getErasure().(RefType).nestedName() and + type = callable.getDeclaringType().getErasure().(RefType).getNestedName() and subtypes = considerSubtypes(callable) and name = callable.getName() and signature = ExternalFlow::paramsString(callable) diff --git a/java/ql/automodel/src/AutomodelApplicationModeCharacteristics.qll b/java/ql/automodel/src/AutomodelApplicationModeCharacteristics.qll index 8c8ad1a2df4..750d776891f 100644 --- a/java/ql/automodel/src/AutomodelApplicationModeCharacteristics.qll +++ b/java/ql/automodel/src/AutomodelApplicationModeCharacteristics.qll @@ -378,7 +378,7 @@ class ApplicationModeMetadataExtractor extends string { package = callable.getDeclaringType().getPackage().getName() and // we're using the erased types because the MaD convention is to not specify type parameters. // Whether something is or isn't a sink doesn't usually depend on the type parameters. - type = callable.getDeclaringType().getErasure().(RefType).nestedName() and + type = callable.getDeclaringType().getErasure().(RefType).getNestedName() and subtypes = AutomodelJavaUtil::considerSubtypes(callable).toString() and name = callable.getName() and signature = ExternalFlow::paramsString(callable) and diff --git a/java/ql/automodel/src/AutomodelFrameworkModeCharacteristics.qll b/java/ql/automodel/src/AutomodelFrameworkModeCharacteristics.qll index 8985e6022eb..7f385a41d1e 100644 --- a/java/ql/automodel/src/AutomodelFrameworkModeCharacteristics.qll +++ b/java/ql/automodel/src/AutomodelFrameworkModeCharacteristics.qll @@ -319,7 +319,7 @@ class FrameworkModeMetadataExtractor extends string { package = callable.getDeclaringType().getPackage().getName() and // we're using the erased types because the MaD convention is to not specify type parameters. // Whether something is or isn't a sink doesn't usually depend on the type parameters. - type = callable.getDeclaringType().getErasure().(RefType).nestedName() and + type = callable.getDeclaringType().getErasure().(RefType).getNestedName() and subtypes = AutomodelJavaUtil::considerSubtypes(callable).toString() and name = callable.getName() and signature = ExternalFlow::paramsString(callable) and diff --git a/java/ql/lib/change-notes/2024-09-16-nestedName.md b/java/ql/lib/change-notes/2024-09-16-nestedName.md new file mode 100644 index 00000000000..26e384e99da --- /dev/null +++ b/java/ql/lib/change-notes/2024-09-16-nestedName.md @@ -0,0 +1,4 @@ +--- +category: deprecated +--- +* The `RefType.nestedName()` predicate has been deprecated, and `RefType.getNestedName()` added to replace it. diff --git a/java/ql/lib/semmle/code/java/Annotation.qll b/java/ql/lib/semmle/code/java/Annotation.qll index de7dd47a93e..f39b1f3420a 100644 --- a/java/ql/lib/semmle/code/java/Annotation.qll +++ b/java/ql/lib/semmle/code/java/Annotation.qll @@ -255,7 +255,7 @@ class Annotatable extends Element { */ predicate hasAnnotation(string package, string name) { exists(AnnotationType at | at = this.getAnAnnotation().getType() | - at.nestedName() = name and at.getPackage().getName() = package + at.getNestedName() = name and at.getPackage().getName() = package ) } diff --git a/java/ql/lib/semmle/code/java/Type.qll b/java/ql/lib/semmle/code/java/Type.qll index 5976bc12f00..f2709d3dda1 100644 --- a/java/ql/lib/semmle/code/java/Type.qll +++ b/java/ql/lib/semmle/code/java/Type.qll @@ -592,7 +592,7 @@ class RefType extends Type, Annotatable, Modifiable, @reftype { * to the name of the enclosing type, which might be a nested type as well. */ predicate hasQualifiedName(string package, string type) { - this.getPackage().hasName(package) and type = this.nestedName() + this.getPackage().hasName(package) and type = this.getNestedName() } /** @@ -601,7 +601,7 @@ class RefType extends Type, Annotatable, Modifiable, @reftype { override string getTypeDescriptor() { result = "L" + this.getPackage().getName().replaceAll(".", "/") + "/" + - this.getSourceDeclaration().nestedName() + ";" + this.getSourceDeclaration().getNestedName() + ";" } /** @@ -615,8 +615,8 @@ class RefType extends Type, Annotatable, Modifiable, @reftype { string getQualifiedName() { exists(string pkgName | pkgName = this.getPackage().getName() | if pkgName = "" - then result = this.nestedName() - else result = pkgName + "." + this.nestedName() + then result = this.getNestedName() + else result = pkgName + "." + this.getNestedName() ) } @@ -627,12 +627,15 @@ class RefType extends Type, Annotatable, Modifiable, @reftype { * Otherwise the name of the nested type is prefixed with a `$` and appended to * the name of the enclosing type, which might be a nested type as well. */ - string nestedName() { + string getNestedName() { not this instanceof NestedType and result = this.getName() or - this.(NestedType).getEnclosingType().nestedName() + "$" + this.getName() = result + this.(NestedType).getEnclosingType().getNestedName() + "$" + this.getName() = result } + /** DEPRECATED: Alias for `getNestedName`. */ + deprecated string nestedName() { result = this.getNestedName() } + /** * Gets the source declaration of this type. * diff --git a/java/ql/lib/semmle/code/java/dataflow/ExternalFlow.qll b/java/ql/lib/semmle/code/java/dataflow/ExternalFlow.qll index f930675998a..28be9a61d75 100644 --- a/java/ql/lib/semmle/code/java/dataflow/ExternalFlow.qll +++ b/java/ql/lib/semmle/code/java/dataflow/ExternalFlow.qll @@ -422,10 +422,10 @@ private predicate elementSpec( private string getNestedName(Type t) { not t instanceof RefType and result = t.toString() or - not t.(Array).getElementType() instanceof NestedType and result = t.(RefType).nestedName() + not t.(Array).getElementType() instanceof NestedType and result = t.(RefType).getNestedName() or result = - t.(Array).getElementType().(NestedType).getEnclosingType().nestedName() + "$" + t.getName() + t.(Array).getElementType().(NestedType).getEnclosingType().getNestedName() + "$" + t.getName() } private string getQualifiedName(Type t) { diff --git a/java/ql/src/Security/CWE/CWE-295/InsecureTrustManager.ql b/java/ql/src/Security/CWE/CWE-295/InsecureTrustManager.ql index 4904c08b195..f8c09907838 100644 --- a/java/ql/src/Security/CWE/CWE-295/InsecureTrustManager.ql +++ b/java/ql/src/Security/CWE/CWE-295/InsecureTrustManager.ql @@ -19,4 +19,4 @@ from InsecureTrustManagerFlow::PathNode source, InsecureTrustManagerFlow::PathNo where InsecureTrustManagerFlow::flowPath(source, sink) select sink, source, sink, "This uses $@, which is defined in $@ and trusts any certificate.", source, "TrustManager", - source.getNode().asExpr().(ClassInstanceExpr).getConstructedType() as type, type.nestedName() + source.getNode().asExpr().(ClassInstanceExpr).getConstructedType() as type, type.getNestedName() diff --git a/java/ql/src/Telemetry/ExternalApi.qll b/java/ql/src/Telemetry/ExternalApi.qll index a548593c36a..f76ced8c66c 100644 --- a/java/ql/src/Telemetry/ExternalApi.qll +++ b/java/ql/src/Telemetry/ExternalApi.qll @@ -30,7 +30,7 @@ class ExternalApi extends Callable { string getApiName() { result = this.getDeclaringType().getPackage() + "." + - this.getDeclaringType().getSourceDeclaration().nestedName() + "#" + this.getName() + + this.getDeclaringType().getSourceDeclaration().getNestedName() + "#" + this.getName() + paramsString(this) } diff --git a/java/ql/src/utils/flowtestcasegenerator/FlowTestCaseUtils.qll b/java/ql/src/utils/flowtestcasegenerator/FlowTestCaseUtils.qll index 8855d7af7a6..3f76cbac394 100644 --- a/java/ql/src/utils/flowtestcasegenerator/FlowTestCaseUtils.qll +++ b/java/ql/src/utils/flowtestcasegenerator/FlowTestCaseUtils.qll @@ -101,7 +101,7 @@ string getShortNameIfPossible(Type t) { getRootSourceDeclaration(t) = any(TestCase tc).getADesiredImport() and exists(RefType replaced, string nestedName | replaced = replaceTypeVariable(t).getSourceDeclaration() and - nestedName = replaced.nestedName().replaceAll("$", ".") + nestedName = replaced.getNestedName().replaceAll("$", ".") | if isImportable(getRootSourceDeclaration(t)) then result = nestedName diff --git a/java/ql/src/utils/modeleditor/ModelEditor.qll b/java/ql/src/utils/modeleditor/ModelEditor.qll index dd4d405b83e..d5286e9024a 100644 --- a/java/ql/src/utils/modeleditor/ModelEditor.qll +++ b/java/ql/src/utils/modeleditor/ModelEditor.qll @@ -27,7 +27,7 @@ class Endpoint extends Callable { /** * Gets the type name of this endpoint. */ - string getTypeName() { result = this.getDeclaringType().nestedName() } + string getTypeName() { result = this.getDeclaringType().getNestedName() } /** * Gets the parameter types of this endpoint. diff --git a/java/ql/src/utils/modelgenerator/internal/CaptureModelsSpecific.qll b/java/ql/src/utils/modelgenerator/internal/CaptureModelsSpecific.qll index 2be162d5f9b..763960df0d8 100644 --- a/java/ql/src/utils/modelgenerator/internal/CaptureModelsSpecific.qll +++ b/java/ql/src/utils/modelgenerator/internal/CaptureModelsSpecific.qll @@ -154,7 +154,7 @@ private string isExtensible(Callable c) { private predicate qualifiedName(Callable c, string package, string type) { exists(RefType t | t = c.getDeclaringType() | package = t.getCompilationUnit().getPackage().getName() and - type = t.getErasure().(J::RefType).nestedName() + type = t.getErasure().(J::RefType).getNestedName() ) } diff --git a/java/ql/test/library-tests/neutrals/neutralsinks/NeutralSinksTest.ql b/java/ql/test/library-tests/neutrals/neutralsinks/NeutralSinksTest.ql index a345d6df1fc..ac56b93e642 100644 --- a/java/ql/test/library-tests/neutrals/neutralsinks/NeutralSinksTest.ql +++ b/java/ql/test/library-tests/neutrals/neutralsinks/NeutralSinksTest.ql @@ -26,7 +26,7 @@ module NeutralSinkTest implements TestSig { exists(Call call, Callable callable | call.getCallee() = callable and neutralModel(callable.getDeclaringType().getCompilationUnit().getPackage().getName(), - callable.getDeclaringType().getSourceDeclaration().nestedName(), callable.getName(), + callable.getDeclaringType().getSourceDeclaration().getNestedName(), callable.getName(), [paramsString(callable), ""], "sink", _) and call.getLocation() = location and element = call.toString() and