Skip to content

Commit 68a7734

Browse files
authored
Merge pull request github#14849 from github/kaeluka/automodel-extraction-skip-primitive-types-candidates
Java Automodel extraction: remove primitives in framework mode
2 parents 59ee3e1 + 2e5971b commit 68a7734

File tree

6 files changed

+30
-18
lines changed

6 files changed

+30
-18
lines changed

java/ql/automodel/src/AutomodelFrameworkModeCharacteristics.qll

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,21 @@ newtype JavaRelatedLocationType =
2424
ClassDoc()
2525

2626
newtype TFrameworkModeEndpoint =
27-
TExplicitParameter(Parameter p) or
27+
TExplicitParameter(Parameter p) {
28+
not p.getType() instanceof PrimitiveType and
29+
not p.getType() instanceof BoxedType and
30+
not p.getType() instanceof NumberType
31+
} or
2832
TQualifier(Callable c) { not c instanceof Constructor } or
29-
TReturnValue(Callable c) or
33+
TReturnValue(Callable c) {
34+
c instanceof Constructor
35+
or
36+
c instanceof Method and
37+
(
38+
not c.getReturnType() instanceof VoidType and
39+
not c.getReturnType() instanceof PrimitiveType
40+
)
41+
} or
3042
TOverridableParameter(Method m, Parameter p) {
3143
p.getCallable() = m and
3244
m instanceof ModelExclusions::ModelApi and

java/ql/automodel/test/AutomodelFrameworkModeExtraction/AutomodelFrameworkModeExtractCandidates.expected

Lines changed: 7 additions & 10 deletions
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
| java/io/File.java:4:16:4:24 | compareTo | known non-sink\nrelated locations: $@, $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@, $@. | java/io/File.java:4:16:4:24 | compareTo | MethodDoc | java/io/File.java:4:16:4:24 | compareTo | ClassDoc | file://java.io:1:1:1:1 | java.io | package | file://File:1:1:1:1 | File | type | file://true:1:1:1:1 | true | subtypes | file://compareTo:1:1:1:1 | compareTo | name | file://(File):1:1:1:1 | (File) | signature | file://:1:1:1:1 | | input | file://Parameter[this]:1:1:1:1 | Parameter[this] | output | file://this:1:1:1:1 | this | parameterName | file://sourceModel:1:1:1:1 | sourceModel | extensibleType |
2-
| java/io/File.java:4:16:4:24 | compareTo | known non-sink\nrelated locations: $@, $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@, $@. | java/io/File.java:4:16:4:24 | compareTo | MethodDoc | java/io/File.java:4:16:4:24 | compareTo | ClassDoc | file://java.io:1:1:1:1 | java.io | package | file://File:1:1:1:1 | File | type | file://true:1:1:1:1 | true | subtypes | file://compareTo:1:1:1:1 | compareTo | name | file://(File):1:1:1:1 | (File) | signature | file://:1:1:1:1 | | input | file://ReturnValue:1:1:1:1 | ReturnValue | output | file://:1:1:1:1 | | parameterName | file://sourceModel:1:1:1:1 | sourceModel | extensibleType |
32
| java/io/File.java:4:16:4:24 | compareTo | known non-sink\nrelated locations: $@, $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@, $@. | java/io/File.java:4:16:4:24 | compareTo | MethodDoc | java/io/File.java:4:16:4:24 | compareTo | ClassDoc | file://java.io:1:1:1:1 | java.io | package | file://File:1:1:1:1 | File | type | file://true:1:1:1:1 | true | subtypes | file://compareTo:1:1:1:1 | compareTo | name | file://(File):1:1:1:1 | (File) | signature | file://Argument[this]:1:1:1:1 | Argument[this] | input | file://:1:1:1:1 | | output | file://this:1:1:1:1 | this | parameterName | file://sinkModel:1:1:1:1 | sinkModel | extensibleType |
43
| java/io/File.java:5:9:5:21 | pathname | known non-sink\nrelated locations: $@, $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@, $@. | java/io/File.java:5:9:5:21 | pathname | MethodDoc | java/io/File.java:5:9:5:21 | pathname | ClassDoc | file://java.io:1:1:1:1 | java.io | package | file://File:1:1:1:1 | File | type | file://true:1:1:1:1 | true | subtypes | file://compareTo:1:1:1:1 | compareTo | name | file://(File):1:1:1:1 | (File) | signature | file://:1:1:1:1 | | input | file://Parameter[0]:1:1:1:1 | Parameter[0] | output | file://pathname:1:1:1:1 | pathname | parameterName | file://sourceModel:1:1:1:1 | sourceModel | extensibleType |
54
| java/io/File.java:5:9:5:21 | pathname | known non-sink\nrelated locations: $@, $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@, $@. | java/io/File.java:5:9:5:21 | pathname | MethodDoc | java/io/File.java:5:9:5:21 | pathname | ClassDoc | file://java.io:1:1:1:1 | java.io | package | file://File:1:1:1:1 | File | type | file://true:1:1:1:1 | true | subtypes | file://compareTo:1:1:1:1 | compareTo | name | file://(File):1:1:1:1 | (File) | signature | file://Argument[0]:1:1:1:1 | Argument[0] | input | file://:1:1:1:1 | | output | file://pathname:1:1:1:1 | pathname | parameterName | file://sinkModel:1:1:1:1 | sinkModel | extensibleType |

java/ql/automodel/test/AutomodelFrameworkModeExtraction/com/github/codeql/test/PublicClass.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
public class PublicClass {
44
public void stuff(String arg) { // `arg` is a sink candidate, `this` is a candidate, `arg` is a source candidate (overrideable method)
55
System.out.println(arg);
6-
} // method stuff is a candidate source
6+
}
77

88
public static void staticStuff(String arg) { // `arg` is a candidate, `this` is not a candidate (static method), `arg` is not a source candidate (static methods can not be overloaded)
99
System.out.println(arg);
10-
} // method staticStuff is a candidate source
10+
}
1111

1212
// `arg` and `this` are candidates because the method is protected (may be called from downstream repositories). The return value is a candidate source for the same reason.
1313
protected void nonPublicStuff(String arg) {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.github.codeql.test;
22

33
public interface PublicInterface {
4-
public void stuff(String arg); // `arg` is a candidate, `this` is a candidate, method stuff is a candidate source, `arg` is a source candidate (overrideable method)
4+
public int stuff(String arg); // `arg` is a candidate, `this` is a candidate, method stuff is _not_ a candidate source (primitive return type), `arg` is a source candidate (overridable method)
55

66
public static void staticStuff(String arg) { // `arg` is a candidate, `this` is not a candidate (static method)
77
System.out.println(arg);
8-
} // method staticStuff is a candidate source
8+
}
99
}

java/ql/automodel/test/AutomodelFrameworkModeExtraction/java/io/File.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,9 @@ public int compareTo( // `this` is a negative example - this is modeled as a neu
55
File pathname // negative example - this is modeled as a neutral model
66
) {
77
return 0;
8-
} // also a negative example for ReturnValue source
8+
}
9+
10+
public boolean setLastModified(long time) {
11+
return false;
12+
} // return value is not a source candidate because it's a primitive
913
}

0 commit comments

Comments
 (0)