You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/codeql/codeql-language-guides/basic-query-for-java-code.rst
+15-11Lines changed: 15 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,7 +46,11 @@ Running a quick query
46
46
where
47
47
ma.getMethod().hasName("equals") and
48
48
ma.getArgument(0).(StringLiteral).getValue() = ""
49
-
select ma, "This comparison to empty string is inefficient, use isEmpty() instead."
49
+
from MethodCall mc
50
+
where
51
+
mc.getMethod().hasName("equals") and
52
+
mc.getArgument(0).(StringLiteral).getValue() = ""
53
+
select mc, "This comparison to empty string is inefficient, use isEmpty() instead."
50
54
51
55
Note that CodeQL treats Java and Kotlin as part of the same language, so even though this query starts with ``import java``, it will work for both Java and Kotlin code.
| ``where ma.getMethod().hasName("equals") and ma.getArgument(0).(StringLiteral).getValue() = ""`` | Defines a condition on the variables. | ``ma.getMethod().hasName("equals")`` restricts ``ma`` to only calls to methods call ``equals``. |
83
+
| ``where mc.getMethod().hasName("equals") and mc.getArgument(0).(StringLiteral).getValue() = ""`` | Defines a condition on the variables. | ``mc.getMethod().hasName("equals")`` restricts ``mc`` to only calls to methods call ``equals``. |
80
84
||||
81
-
||| ``ma.getArgument(0).(StringLiteral).getValue() = ""`` says the argument must be literal ``""``. |
85
+
||| ``mc.getArgument(0).(StringLiteral).getValue() = ""`` says the argument must be literal ``""``. |
| ``select ma, "This comparison to empty string is inefficient, use isEmpty() instead."`` | Defines what to report for each match. | Reports the resulting ``.equals`` expression with a string that explains the problem. |
87
+
| ``select mc, "This comparison to empty string is inefficient, use isEmpty() instead."`` | Defines what to report for each match. | Reports the resulting ``.equals`` expression with a string that explains the problem. |
84
88
||||
85
89
|| ``select`` statements for queries that are used to find instances of poor coding practice are always in the form: ||
.. |result-col-1| replace:: The first column corresponds to the expression ``ma`` and is linked to the location in the source code of the project where ``ma`` occurs.
148
+
.. |result-col-1| replace:: The first column corresponds to the expression ``mc`` and is linked to the location in the source code of the project where ``mc`` occurs.
0 commit comments