Skip to content

Commit a5a6fd3

Browse files
committed
Enable recognising jakarta.persistence in dead-code queries
1 parent fb6296a commit a5a6fd3

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

java/ql/lib/semmle/code/java/deadcode/DeadField.qll

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import semmle.code.java.deadcode.DeadCode
33
import semmle.code.java.frameworks.javaee.Persistence
44
import semmle.code.java.frameworks.JAXB
55
import semmle.code.java.frameworks.jackson.JacksonSerializability
6+
import semmle.code.java.frameworks.javaee.Persistence
67

78
/**
89
* A field that is from a source file.
@@ -161,10 +162,10 @@ class JpaReadField extends ReflectivelyReadField {
161162
this = entity.getAField() and
162163
(
163164
entity.getAccessType() = "field" or
164-
this.hasAnnotation("javax.persistence", "Access")
165+
this.hasAnnotation(getAPersistencePackageName(), "Access")
165166
)
166167
|
167-
not this.hasAnnotation("javax.persistence", "Transient") and
168+
not this.hasAnnotation(getAPersistencePackageName(), "Transient") and
168169
not this.isStatic() and
169170
not this.isFinal()
170171
)

java/ql/lib/semmle/code/java/deadcode/EntryPoints.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import semmle.code.java.deadcode.StrutsEntryPoints
77
import semmle.code.java.deadcode.TestEntryPoints
88
import semmle.code.java.deadcode.WebEntryPoints
99
import semmle.code.java.frameworks.javaee.JavaServerFaces
10+
import semmle.code.java.frameworks.javaee.Persistence
1011
import semmle.code.java.frameworks.JAXB
1112
import semmle.code.java.frameworks.JaxWS
1213
import semmle.code.java.JMX
@@ -395,7 +396,7 @@ class PersistencePropertyMethod extends CallableEntryPoint {
395396
this = e.getACallable() and
396397
(
397398
e.getAccessType() = "property" or
398-
this.hasAnnotation("javax.persistence", "Access")
399+
this.hasAnnotation(getAPersistencePackageName(), "Access")
399400
) and
400401
(
401402
this.getName().matches("get%") or

java/ql/lib/semmle/code/java/frameworks/javaee/Persistence.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
import java
66

7-
private string getAPersistencePackageName() {
7+
/**
8+
* Gets a JavaEE Persistence API package name.
9+
*/
10+
string getAPersistencePackageName() {
811
result = ["javax.persistence", "jakarta.persistence"]
912
}
1013

0 commit comments

Comments
 (0)