-
Notifications
You must be signed in to change notification settings - Fork 2k
Add MethodAccessSystemGetProperty predicate #4898
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -211,6 +211,21 @@ class MethodSystemGetProperty extends Method { | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Any method access to a method named `getProperty` on class `java.lang.System`. | ||||||
| */ | ||||||
| class MethodAccessSystemGetProperty extends MethodAccess { | ||||||
| MethodAccessSystemGetProperty() { getMethod() instanceof MethodSystemGetProperty } | ||||||
|
|
||||||
| /** | ||||||
| * Holds true if this is a compile-time constant call for the specified `propertyName`. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this is resolved. |
||||||
| * Eg. `System.getProperty("user.dir")`. | ||||||
|
JLLeitschuh marked this conversation as resolved.
Outdated
|
||||||
| */ | ||||||
| predicate hasCompileTimeConstantGetPropertyName(string propertyName) { | ||||||
| this.getArgument(0).(CompileTimeConstantExpr).getStringValue() = propertyName | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Any method named `exit` on class `java.lang.Runtime` or `java.lang.System`. | ||||||
| */ | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,5 +16,6 @@ class PrintAstConfigurationOverride extends PrintAstConfiguration { | |
| /** | ||
| * TWEAK THIS PREDICATE AS NEEDED. | ||
| */ | ||
| override predicate shouldPrint(Element e, Location l) { super.shouldPrint(e, l) } | ||
| override predicate shouldPrint(Element e, Location l) { super.shouldPrint(e, l) and | ||
| not l.getFile().getBaseName().matches("SystemGetPropertyCall.java") } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Accidentally committed?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope, this is intentional. Do you want me to just update the test result?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, please update the test result instead.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be resolved now. |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| | jdk/SystemGetPropertyCall.java:7:9:7:38 | getProperty(...) | | ||
| | jdk/SystemGetPropertyCall.java:11:9:11:46 | getProperty(...) | | ||
| | jdk/SystemGetPropertyCall.java:15:9:15:45 | getProperty(...) | |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| /** | ||
| * @name SystemCall | ||
| * @description Test the definition of System Get Property | ||
| */ | ||
|
|
||
| import default | ||
|
JLLeitschuh marked this conversation as resolved.
Outdated
|
||
|
|
||
| from MethodAccessSystemGetProperty ma | ||
| where ma.hasCompileTimeConstantGetPropertyName("user.dir") | ||
| select ma | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package jdk; | ||
|
|
||
| public class SystemGetPropertyCall { | ||
| private static final String USER_DIR_PROPERTY = "user.dir"; | ||
|
|
||
| void a() { | ||
| System.getProperty("user.dir"); | ||
| } | ||
|
|
||
| void b() { | ||
| System.getProperty("user.dir", "HOME"); | ||
| } | ||
|
|
||
| void c() { | ||
| System.getProperty(USER_DIR_PROPERTY); | ||
| } | ||
|
|
||
| void d() { | ||
| System.getProperty("random.property"); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.