Skip to content

Commit 94e3d86

Browse files
authored
Merge pull request #21319 from owen-mc/java/javax-jakarta
Java: Always use both "javax" and "jakarta" at the beginning of Jave EE packages
2 parents b34777e + 91c731f commit 94e3d86

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+347
-204
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Some modelling which previously only worked for Java EE packages beginning with "javax" will now also work for Java EE packages beginning with "jakarta" as well. This may lead to some alert changes.

java/ql/lib/experimental/quantum/JCA.qll

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ module JCAModel {
295295

296296
class CipherGetInstanceCall extends MethodCall {
297297
CipherGetInstanceCall() {
298-
this.getCallee().hasQualifiedName("javax.crypto", "Cipher", "getInstance")
298+
this.getCallee().hasQualifiedName(javaxOrJakarta() + ".crypto", "Cipher", "getInstance")
299299
}
300300

301301
Expr getAlgorithmArg() { result = this.getArgument(0) }
@@ -307,7 +307,8 @@ module JCAModel {
307307
private class CipherOperationCall extends MethodCall {
308308
CipherOperationCall() {
309309
this.getMethod()
310-
.hasQualifiedName("javax.crypto", "Cipher", ["update", "doFinal", "wrap", "unwrap"])
310+
.hasQualifiedName(javaxOrJakarta() + ".crypto", "Cipher",
311+
["update", "doFinal", "wrap", "unwrap"])
311312
}
312313

313314
predicate isIntermediate() { this.getMethod().getName() = "update" }
@@ -474,7 +475,9 @@ module JCAModel {
474475
* An access to the `javax.crypto.Cipher` class.
475476
*/
476477
private class CipherAccess extends TypeAccess {
477-
CipherAccess() { this.getType().(Class).hasQualifiedName("javax.crypto", "Cipher") }
478+
CipherAccess() {
479+
this.getType().(Class).hasQualifiedName(javaxOrJakarta() + ".crypto", "Cipher")
480+
}
478481
}
479482

480483
/**
@@ -708,7 +711,9 @@ module JCAModel {
708711
// and through setter methods
709712
class IvParameterSpecInstance extends NonceParameterInstantiation {
710713
IvParameterSpecInstance() {
711-
super.getConstructedType().hasQualifiedName("javax.crypto.spec", "IvParameterSpec")
714+
super
715+
.getConstructedType()
716+
.hasQualifiedName(javaxOrJakarta() + ".crypto.spec", "IvParameterSpec")
712717
}
713718

714719
override DataFlow::Node getInputNode() { result.asExpr() = super.getArgument(0) }
@@ -717,15 +722,18 @@ module JCAModel {
717722
// TODO: this also specifies the tag length for GCM
718723
class GCMParameterSpecInstance extends NonceParameterInstantiation {
719724
GCMParameterSpecInstance() {
720-
super.getConstructedType().hasQualifiedName("javax.crypto.spec", "GCMParameterSpec")
725+
super
726+
.getConstructedType()
727+
.hasQualifiedName(javaxOrJakarta() + ".crypto.spec", "GCMParameterSpec")
721728
}
722729

723730
override DataFlow::Node getInputNode() { result.asExpr() = super.getArgument(1) }
724731
}
725732

726733
class IvParameterSpecGetIvCall extends MethodCall {
727734
IvParameterSpecGetIvCall() {
728-
this.getMethod().hasQualifiedName("javax.crypto.spec", "IvParameterSpec", "getIV")
735+
this.getMethod()
736+
.hasQualifiedName(javaxOrJakarta() + ".crypto.spec", "IvParameterSpec", "getIV")
729737
}
730738
}
731739

@@ -797,7 +805,9 @@ module JCAModel {
797805
}
798806

799807
class CipherInitCall extends MethodCall {
800-
CipherInitCall() { this.getCallee().hasQualifiedName("javax.crypto", "Cipher", "init") }
808+
CipherInitCall() {
809+
this.getCallee().hasQualifiedName(javaxOrJakarta() + ".crypto", "Cipher", "init")
810+
}
801811

802812
/**
803813
* Returns the mode argument to the `init` method
@@ -966,7 +976,9 @@ module JCAModel {
966976

967977
class DHGenParameterSpecInstance extends KeyGeneratorParameterSpecClassInstanceExpr {
968978
DHGenParameterSpecInstance() {
969-
super.getConstructedType().hasQualifiedName("javax.crypto.spec", "DHGenParameterSpec")
979+
super
980+
.getConstructedType()
981+
.hasQualifiedName(javaxOrJakarta() + ".crypto.spec", "DHGenParameterSpec")
970982
}
971983

972984
Expr getPrimeSizeArg() { result = this.getArgument(0) }
@@ -1067,7 +1079,7 @@ module JCAModel {
10671079
//TODO: Link getAlgorithm from KeyPairGenerator to algorithm instances or AVCs? High priority.
10681080
class KeyGeneratorGetInstanceCall extends MethodCall {
10691081
KeyGeneratorGetInstanceCall() {
1070-
this.getCallee().hasQualifiedName("javax.crypto", "KeyGenerator", "getInstance")
1082+
this.getCallee().hasQualifiedName(javaxOrJakarta() + ".crypto", "KeyGenerator", "getInstance")
10711083
or
10721084
this.getCallee().hasQualifiedName("java.security", "KeyPairGenerator", "getInstance")
10731085
}
@@ -1082,7 +1094,8 @@ module JCAModel {
10821094
this.getCallee().hasQualifiedName("java.security", "KeyPairGenerator", "initialize") and
10831095
keyType = Crypto::TAsymmetricKeyType()
10841096
or
1085-
this.getCallee().hasQualifiedName("javax.crypto", "KeyGenerator", ["init", "initialize"]) and
1097+
this.getCallee()
1098+
.hasQualifiedName(javaxOrJakarta() + ".crypto", "KeyGenerator", ["init", "initialize"]) and
10861099
keyType = Crypto::TSymmetricKeyType()
10871100
}
10881101

@@ -1111,7 +1124,7 @@ module JCAModel {
11111124
Crypto::KeyArtifactType type;
11121125

11131126
KeyGeneratorGenerateCall() {
1114-
this.getCallee().hasQualifiedName("javax.crypto", "KeyGenerator", "generateKey") and
1127+
this.getCallee().hasQualifiedName(javaxOrJakarta() + ".crypto", "KeyGenerator", "generateKey") and
11151128
type instanceof Crypto::TSymmetricKeyType
11161129
or
11171130
this.getCallee()
@@ -1176,7 +1189,7 @@ module JCAModel {
11761189
class KeySpecInstantiation extends ClassInstanceExpr {
11771190
KeySpecInstantiation() {
11781191
this.getConstructedType()
1179-
.hasQualifiedName("javax.crypto.spec",
1192+
.hasQualifiedName(javaxOrJakarta() + ".crypto.spec",
11801193
["PBEKeySpec", "SecretKeySpec", "PBEKeySpec", "DESedeKeySpec"])
11811194
}
11821195

@@ -1227,15 +1240,17 @@ module JCAModel {
12271240

12281241
class SecretKeyFactoryGetInstanceCall extends MethodCall {
12291242
SecretKeyFactoryGetInstanceCall() {
1230-
this.getCallee().hasQualifiedName("javax.crypto", "SecretKeyFactory", "getInstance")
1243+
this.getCallee()
1244+
.hasQualifiedName(javaxOrJakarta() + ".crypto", "SecretKeyFactory", "getInstance")
12311245
}
12321246

12331247
Expr getAlgorithmArg() { result = this.getArgument(0) }
12341248
}
12351249

12361250
class SecretKeyFactoryGenerateSecretCall extends MethodCall {
12371251
SecretKeyFactoryGenerateSecretCall() {
1238-
this.getCallee().hasQualifiedName("javax.crypto", "SecretKeyFactory", "generateSecret")
1252+
this.getCallee()
1253+
.hasQualifiedName(javaxOrJakarta() + ".crypto", "SecretKeyFactory", "generateSecret")
12391254
}
12401255

12411256
Expr getKeySpecArg() { result = this.getArgument(0) }
@@ -1430,15 +1445,15 @@ module JCAModel {
14301445

14311446
class KeyAgreementInitCall extends MethodCall {
14321447
KeyAgreementInitCall() {
1433-
this.getCallee().hasQualifiedName("javax.crypto", "KeyAgreement", "init")
1448+
this.getCallee().hasQualifiedName(javaxOrJakarta() + ".crypto", "KeyAgreement", "init")
14341449
}
14351450

14361451
Expr getServerKeyArg() { result = this.getArgument(0) }
14371452
}
14381453

14391454
class KeyAgreementGetInstanceCall extends MethodCall {
14401455
KeyAgreementGetInstanceCall() {
1441-
this.getCallee().hasQualifiedName("javax.crypto", "KeyAgreement", "getInstance")
1456+
this.getCallee().hasQualifiedName(javaxOrJakarta() + ".crypto", "KeyAgreement", "getInstance")
14421457
}
14431458

14441459
Expr getAlgorithmArg() { result = super.getArgument(0) }
@@ -1482,7 +1497,8 @@ module JCAModel {
14821497
class KeyAgreementCall extends MethodCall {
14831498
KeyAgreementCall() {
14841499
this.getCallee()
1485-
.hasQualifiedName("javax.crypto", "KeyAgreement", ["generateSecret", "doPhase"])
1500+
.hasQualifiedName(javaxOrJakarta() + ".crypto", "KeyAgreement",
1501+
["generateSecret", "doPhase"])
14861502
}
14871503

14881504
predicate isIntermediate() { this.getCallee().getName() = "doPhase" }
@@ -1647,7 +1663,9 @@ module JCAModel {
16471663
}
16481664

16491665
class MacGetInstanceCall extends MethodCall {
1650-
MacGetInstanceCall() { this.getCallee().hasQualifiedName("javax.crypto", "Mac", "getInstance") }
1666+
MacGetInstanceCall() {
1667+
this.getCallee().hasQualifiedName(javaxOrJakarta() + ".crypto", "Mac", "getInstance")
1668+
}
16511669

16521670
Expr getAlgorithmArg() { result = this.getArgument(0) }
16531671

@@ -1663,7 +1681,7 @@ module JCAModel {
16631681
}
16641682

16651683
class MacInitCall extends MethodCall {
1666-
MacInitCall() { this.getCallee().hasQualifiedName("javax.crypto", "Mac", "init") }
1684+
MacInitCall() { this.getCallee().hasQualifiedName(javaxOrJakarta() + ".crypto", "Mac", "init") }
16671685

16681686
Expr getKeyArg() {
16691687
result = this.getArgument(0) and this.getMethod().getParameterType(0).hasName("Key")
@@ -1691,7 +1709,7 @@ module JCAModel {
16911709
Expr output;
16921710

16931711
MacOperationCall() {
1694-
super.getMethod().getDeclaringType().hasQualifiedName("javax.crypto", "Mac") and
1712+
super.getMethod().getDeclaringType().hasQualifiedName(javaxOrJakarta() + ".crypto", "Mac") and
16951713
(
16961714
super.getMethod().hasStringSignature(["doFinal()", "doFinal(byte[])"]) and this = output
16971715
or

java/ql/lib/semmle/code/java/J2EE.qll

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,52 +6,67 @@ module;
66

77
import Type
88

9+
/** Gets "java" or "jakarta". */
10+
string javaxOrJakarta() { result = ["javax", "jakarta"] }
11+
912
/** An entity bean. */
1013
class EntityBean extends Class {
1114
EntityBean() {
12-
exists(Interface i | i.hasQualifiedName("javax.ejb", "EntityBean") | this.hasSupertype+(i))
15+
exists(Interface i | i.hasQualifiedName(javaxOrJakarta() + ".ejb", "EntityBean") |
16+
this.hasSupertype+(i)
17+
)
1318
}
1419
}
1520

1621
/** An enterprise bean. */
1722
class EnterpriseBean extends RefType {
1823
EnterpriseBean() {
19-
exists(Interface i | i.hasQualifiedName("javax.ejb", "EnterpriseBean") | this.hasSupertype+(i))
24+
exists(Interface i | i.hasQualifiedName(javaxOrJakarta() + ".ejb", "EnterpriseBean") |
25+
this.hasSupertype+(i)
26+
)
2027
}
2128
}
2229

2330
/** A local EJB home interface. */
2431
class LocalEjbHomeInterface extends Interface {
2532
LocalEjbHomeInterface() {
26-
exists(Interface i | i.hasQualifiedName("javax.ejb", "EJBLocalHome") | this.hasSupertype+(i))
33+
exists(Interface i | i.hasQualifiedName(javaxOrJakarta() + ".ejb", "EJBLocalHome") |
34+
this.hasSupertype+(i)
35+
)
2736
}
2837
}
2938

3039
/** A remote EJB home interface. */
3140
class RemoteEjbHomeInterface extends Interface {
3241
RemoteEjbHomeInterface() {
33-
exists(Interface i | i.hasQualifiedName("javax.ejb", "EJBHome") | this.hasSupertype+(i))
42+
exists(Interface i | i.hasQualifiedName(javaxOrJakarta() + ".ejb", "EJBHome") |
43+
this.hasSupertype+(i)
44+
)
3445
}
3546
}
3647

3748
/** A local EJB interface. */
3849
class LocalEjbInterface extends Interface {
3950
LocalEjbInterface() {
40-
exists(Interface i | i.hasQualifiedName("javax.ejb", "EJBLocalObject") | this.hasSupertype+(i))
51+
exists(Interface i | i.hasQualifiedName(javaxOrJakarta() + ".ejb", "EJBLocalObject") |
52+
this.hasSupertype+(i)
53+
)
4154
}
4255
}
4356

4457
/** A remote EJB interface. */
4558
class RemoteEjbInterface extends Interface {
4659
RemoteEjbInterface() {
47-
exists(Interface i | i.hasQualifiedName("javax.ejb", "EJBObject") | this.hasSupertype+(i))
60+
exists(Interface i | i.hasQualifiedName(javaxOrJakarta() + ".ejb", "EJBObject") |
61+
this.hasSupertype+(i)
62+
)
4863
}
4964
}
5065

5166
/** A message bean. */
5267
class MessageBean extends Class {
5368
MessageBean() {
54-
exists(Interface i | i.hasQualifiedName("javax.ejb", "MessageDrivenBean") |
69+
exists(Interface i | i.hasQualifiedName(javaxOrJakarta() + ".ejb", "MessageDrivenBean") |
5570
this.hasSupertype+(i)
5671
)
5772
}
@@ -60,6 +75,8 @@ class MessageBean extends Class {
6075
/** A session bean. */
6176
class SessionBean extends Class {
6277
SessionBean() {
63-
exists(Interface i | i.hasQualifiedName("javax.ejb", "SessionBean") | this.hasSupertype+(i))
78+
exists(Interface i | i.hasQualifiedName(javaxOrJakarta() + ".ejb", "SessionBean") |
79+
this.hasSupertype+(i)
80+
)
6481
}
6582
}

java/ql/lib/semmle/code/java/JMX.qll

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class MBean extends ManagedBean {
1818
class MXBean extends ManagedBean {
1919
MXBean() {
2020
this.getQualifiedName().matches("%MXBean%") or
21-
this.getAnAnnotation().getType().hasQualifiedName("javax.management", "MXBean")
21+
this.getAnAnnotation().getType().hasQualifiedName(javaxOrJakarta() + ".management", "MXBean")
2222
}
2323
}
2424

@@ -61,7 +61,7 @@ class JmxRegistrationCall extends MethodCall {
6161
class JmxRegistrationMethod extends Method {
6262
JmxRegistrationMethod() {
6363
// A direct registration with the `MBeanServer`.
64-
this.getDeclaringType().hasQualifiedName("javax.management", "MBeanServer") and
64+
this.getDeclaringType().hasQualifiedName(javaxOrJakarta() + ".management", "MBeanServer") and
6565
this.getName() = "registerMBean"
6666
or
6767
// The `MBeanServer` is often wrapped by an application specific management class, so identify
@@ -78,7 +78,7 @@ class JmxRegistrationMethod extends Method {
7878
*/
7979
int getObjectPosition() {
8080
// Passed as the first argument to `registerMBean`.
81-
this.getDeclaringType().hasQualifiedName("javax.management", "MBeanServer") and
81+
this.getDeclaringType().hasQualifiedName(javaxOrJakarta() + ".management", "MBeanServer") and
8282
this.getName() = "registerMBean" and
8383
result = 0
8484
or
@@ -92,16 +92,20 @@ class JmxRegistrationMethod extends Method {
9292
/** The class `javax.management.remote.JMXConnectorFactory`. */
9393
class TypeJmxConnectorFactory extends Class {
9494
TypeJmxConnectorFactory() {
95-
this.hasQualifiedName("javax.management.remote", "JMXConnectorFactory")
95+
this.hasQualifiedName(javaxOrJakarta() + ".management.remote", "JMXConnectorFactory")
9696
}
9797
}
9898

9999
/** The class `javax.management.remote.JMXServiceURL`. */
100100
class TypeJmxServiceUrl extends Class {
101-
TypeJmxServiceUrl() { this.hasQualifiedName("javax.management.remote", "JMXServiceURL") }
101+
TypeJmxServiceUrl() {
102+
this.hasQualifiedName(javaxOrJakarta() + ".management.remote", "JMXServiceURL")
103+
}
102104
}
103105

104106
/** The class `javax.management.remote.rmi.RMIConnector`. */
105107
class TypeRmiConnector extends Class {
106-
TypeRmiConnector() { this.hasQualifiedName("javax.management.remote.rmi", "RMIConnector") }
108+
TypeRmiConnector() {
109+
this.hasQualifiedName(javaxOrJakarta() + ".management.remote.rmi", "RMIConnector")
110+
}
107111
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ class FacesComponentReflectivelyConstructedClass extends ReflectivelyConstructed
316316
* Entry point for EJB home interfaces.
317317
*/
318318
class EjbHome extends Interface, EntryPoint {
319-
EjbHome() { this.getAnAncestor().hasQualifiedName("javax.ejb", "EJBHome") }
319+
EjbHome() { this.getAnAncestor().hasQualifiedName(javaxOrJakarta() + ".ejb", "EJBHome") }
320320

321321
override Callable getALiveCallable() { result = this.getACallable() }
322322
}
@@ -325,7 +325,7 @@ class EjbHome extends Interface, EntryPoint {
325325
* Entry point for EJB object interfaces.
326326
*/
327327
class EjbObject extends Interface, EntryPoint {
328-
EjbObject() { this.getAnAncestor().hasQualifiedName("javax.ejb", "EJBObject") }
328+
EjbObject() { this.getAnAncestor().hasQualifiedName(javaxOrJakarta() + ".ejb", "EJBObject") }
329329

330330
override Callable getALiveCallable() { result = this.getACallable() }
331331
}
@@ -341,7 +341,9 @@ class GsonDeserializationEntryPoint extends ReflectivelyConstructedClass {
341341
class JaxbDeserializationEntryPoint extends ReflectivelyConstructedClass {
342342
JaxbDeserializationEntryPoint() {
343343
// A class can be deserialized by JAXB if it's an `XmlRootElement`...
344-
this.getAnAnnotation().getType().hasQualifiedName("javax.xml.bind.annotation", "XmlRootElement")
344+
this.getAnAnnotation()
345+
.getType()
346+
.hasQualifiedName(javaxOrJakarta() + ".xml.bind.annotation", "XmlRootElement")
345347
or
346348
// ... or the type of an `XmlElement` field.
347349
exists(Field elementField |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class ServletListenerClass extends ReflectivelyConstructedClass {
4545
*/
4646
class ServletFilterClass extends ReflectivelyConstructedClass {
4747
ServletFilterClass() {
48-
this.getAnAncestor().hasQualifiedName("javax.servlet", "Filter") and
48+
this.getAnAncestor().hasQualifiedName(javaxOrJakarta() + ".servlet", "Filter") and
4949
// If we have seen any `web.xml` files, this filter will be considered to be live only if it is
5050
// referred to as a filter-class in at least one. If no `web.xml` files are found, we assume
5151
// that XML extraction was not enabled, and therefore consider all filter classes as live.

0 commit comments

Comments
 (0)