Skip to content

Commit 37baf77

Browse files
authored
Merge pull request github#5273 from intrigus-lgtm/java/unify-main-method-check
Java: Remove duplicate code.
2 parents 3b56e35 + 141f057 commit 37baf77

File tree

3 files changed

+5
-15
lines changed

3 files changed

+5
-15
lines changed

java/ql/src/experimental/Security/CWE/CWE-489/EJBMain.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99

1010
import java
1111
import semmle.code.java.J2EE
12-
import MainLib
12+
import TestLib
1313

1414
/** The `main` method in an Enterprise Java Bean. */
1515
class EnterpriseBeanMainMethod extends Method {
1616
EnterpriseBeanMainMethod() {
1717
this.getDeclaringType() instanceof EnterpriseBean and
18-
isMainMethod(this) and
18+
this instanceof MainMethod and
1919
not isTestMethod(this)
2020
}
2121
}

java/ql/src/experimental/Security/CWE/CWE-489/MainLib.qll renamed to java/ql/src/experimental/Security/CWE/CWE-489/TestLib.qll

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
1-
/** Definitions related to the main method in a test program. */
1+
/** Definitions related to test methods. */
22

33
import java
44

5-
/** Holds if `m` is the main method of a Java class with the signature `public static void main(String[] args)`. */
6-
predicate isMainMethod(Method m) {
7-
m.hasName("main") and
8-
m.isStatic() and
9-
m.getReturnType() instanceof VoidType and
10-
m.isPublic() and
11-
m.getNumberOfParameters() = 1 and
12-
m.getParameter(0).getType() instanceof Array
13-
}
14-
155
/**
166
* Holds if `m` is a test method indicated by:
177
* a) in a test directory such as `src/test/java`

java/ql/src/experimental/Security/CWE/CWE-489/WebComponentMain.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import java
1111
import semmle.code.java.frameworks.Servlets
12-
import MainLib
12+
import TestLib
1313

1414
/** The java type `javax.servlet.Filter`. */
1515
class ServletFilterClass extends Class {
@@ -48,7 +48,7 @@ class WebComponentMainMethod extends Method {
4848
.getASupertype+()
4949
.hasQualifiedName("org.springframework.webflow.execution", "Action") // Spring actions
5050
) and
51-
isMainMethod(this) and
51+
this instanceof MainMethod and
5252
not isTestMethod(this)
5353
}
5454
}

0 commit comments

Comments
 (0)