Skip to content

Commit f2ce125

Browse files
authored
Merge pull request github#3902 from Marcono1234/fix-outdated-query-links
Approved by shati-patel
2 parents fe0c5a9 + 5649254 commit f2ce125

File tree

7 files changed

+59
-59
lines changed

7 files changed

+59
-59
lines changed

docs/language/learn-ql/java/annotations.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ We could then write this query to find all ``@SuppressWarnings`` annotations att
4949
anntp.hasQualifiedName("java.lang", "SuppressWarnings")
5050
select ann, ann.getValue("value")
5151
52-
➤ `See the full query in the query console on LGTM.com <https://lgtm.com/query/632150601>`__. Several of the LGTM.com demo projects use the ``@SuppressWarnings`` annotation. Looking at the ``value``\ s of the annotation element returned by the query, we can see that the *apache/activemq* project uses the ``"rawtypes"`` value described above.
52+
➤ `See the full query in the query console on LGTM.com <https://lgtm.com/query/1775658606775222283/>`__. Several of the LGTM.com demo projects use the ``@SuppressWarnings`` annotation. Looking at the ``value``\ s of the annotation element returned by the query, we can see that the *apache/activemq* project uses the ``"rawtypes"`` value described above.
5353

5454
As another example, this query finds all annotation types that only have a single annotation element, which has name ``value``:
5555

@@ -64,7 +64,7 @@ As another example, this query finds all annotation types that only have a singl
6464
)
6565
select anntp
6666
67-
➤ `See the full query in the query console on LGTM.com <https://lgtm.com/query/669220001>`__.
67+
➤ `See the full query in the query console on LGTM.com <https://lgtm.com/query/2145264152490258283/>`__.
6868

6969
Example: Finding missing ``@Override`` annotations
7070
--------------------------------------------------
@@ -122,7 +122,7 @@ This makes it very easy to write our query for finding methods that override ano
122122
not overriding.getAnAnnotation() instanceof OverrideAnnotation
123123
select overriding, "Method overrides another method, but does not have an @Override annotation."
124124
125-
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/1505752756202/>`__. In practice, this query may yield many results from compiled library code, which aren't very interesting. It's therefore a good idea to add another conjunct ``overriding.fromSource()`` to restrict the result to only report methods for which source code is available.
125+
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/7419756266089837339/>`__. In practice, this query may yield many results from compiled library code, which aren't very interesting. It's therefore a good idea to add another conjunct ``overriding.fromSource()`` to restrict the result to only report methods for which source code is available.
126126

127127
Example: Finding calls to deprecated methods
128128
--------------------------------------------
@@ -192,13 +192,13 @@ For instance, consider this slightly updated example:
192192
.. code-block:: java
193193
194194
class A {
195-
@Deprecated void m() {}
195+
@Deprecated void m() {}
196196
197-
@Deprecated void n() {
198-
m();
199-
}
197+
@Deprecated void n() {
198+
m();
199+
}
200200
201-
@SuppressWarnings("deprecated")
201+
@SuppressWarnings("deprecated")
202202
void r() {
203203
m();
204204
}
@@ -235,7 +235,7 @@ Now we can extend our query to filter out calls in methods carrying a ``Suppress
235235
and not call.getCaller().getAnAnnotation() instanceof SuppressDeprecationWarningAnnotation
236236
select call, "This call invokes a deprecated method."
237237
238-
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/665760001>`__. It's fairly common for projects to contain calls to methods that appear to be deprecated.
238+
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/8706367340403790260/>`__. It's fairly common for projects to contain calls to methods that appear to be deprecated.
239239

240240
Further reading
241241
---------------

docs/language/learn-ql/java/call-graph.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ We can use the ``Callable`` class to write a query that finds methods that are n
7878
where not exists(Callable caller | caller.polyCalls(callee))
7979
select callee
8080
81-
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/665280012/>`__. This simple query typically returns a large number of results.
81+
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/8376915232270534450/>`__. This simple query typically returns a large number of results.
8282

8383
.. pull-quote::
8484

@@ -97,7 +97,7 @@ Running this query on a typical Java project results in lots of hits in the Java
9797
callee.getCompilationUnit().fromSource()
9898
select callee, "Not called."
9999
100-
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/668510015/>`__. This change reduces the number of results returned for most projects.
100+
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/8711624074465690976/>`__. This change reduces the number of results returned for most projects.
101101

102102
We might also notice several unused methods with the somewhat strange name ``<clinit>``: these are class initializers; while they are not explicitly called anywhere in the code, they are called implicitly whenever the surrounding class is loaded. Hence it makes sense to exclude them from our query. While we are at it, we can also exclude finalizers, which are similarly invoked implicitly:
103103

@@ -111,7 +111,7 @@ We might also notice several unused methods with the somewhat strange name ``<cl
111111
not callee.hasName("<clinit>") and not callee.hasName("finalize")
112112
select callee, "Not called."
113113
114-
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/672230002/>`__. This also reduces the number of results returned by most projects.
114+
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/925473733866047471/>`__. This also reduces the number of results returned by most projects.
115115

116116
We may also want to exclude public methods from our query, since they may be external API entry points:
117117

@@ -126,7 +126,7 @@ We may also want to exclude public methods from our query, since they may be ext
126126
not callee.isPublic()
127127
select callee, "Not called."
128128
129-
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/667290016/>`__. This should have a more noticeable effect on the number of results returned.
129+
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/6284320987237954610/>`__. This should have a more noticeable effect on the number of results returned.
130130

131131
A further special case is non-public default constructors: in the singleton pattern, for example, a class is provided with private empty default constructor to prevent it from being instantiated. Since the very purpose of such constructors is their not being called, they should not be flagged up:
132132

@@ -142,7 +142,7 @@ A further special case is non-public default constructors: in the singleton patt
142142
not callee.(Constructor).getNumberOfParameters() = 0
143143
select callee, "Not called."
144144
145-
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/673060008/>`__. This change has a large effect on the results for some projects but little effect on the results for others. Use of this pattern varies widely between different projects.
145+
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/2625028545869146918/>`__. This change has a large effect on the results for some projects but little effect on the results for others. Use of this pattern varies widely between different projects.
146146

147147
Finally, on many Java projects there are methods that are invoked indirectly by reflection. So, while there are no calls invoking these methods, they are, in fact, used. It is in general very hard to identify such methods. A very common special case, however, is JUnit test methods, which are reflectively invoked by a test runner. The CodeQL library for Java has support for recognizing test classes of JUnit and other testing frameworks, which we can employ to filter out methods defined in such classes:
148148

@@ -159,7 +159,7 @@ Finally, on many Java projects there are methods that are invoked indirectly by
159159
not callee.getDeclaringType() instanceof TestClass
160160
select callee, "Not called."
161161
162-
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/665760002/>`__. This should give a further reduction in the number of results returned.
162+
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/2055862421970264112/>`__. This should give a further reduction in the number of results returned.
163163

164164
Further reading
165165
---------------

docs/language/learn-ql/java/expressions-statements.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ We'll start by writing a query that finds less-than expressions (CodeQL class ``
4242
expr.getRightOperand().getType().hasName("long")
4343
select expr
4444
45-
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/672320008/>`__. This query usually finds results on most projects.
45+
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/490866529746563234/>`__. This query usually finds results on most projects.
4646

4747
Notice that we use the predicate ``getType`` (available on all subclasses of ``Expr``) to determine the type of the operands. Types, in turn, define the ``hasName`` predicate, which allows us to identify the primitive types ``int`` and ``long``. As it stands, this query finds *all* less-than expressions comparing ``int`` and ``long``, but in fact we are only interested in comparisons that are part of a loop condition. Also, we want to filter out comparisons where either operand is constant, since these are less likely to be real bugs. The revised query looks like this:
4848

@@ -57,7 +57,7 @@ Notice that we use the predicate ``getType`` (available on all subclasses of ``E
5757
not expr.getAnOperand().isCompileTimeConstant()
5858
select expr
5959
60-
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/690010001/>`__. Notice that fewer results are found.
60+
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/4315986481180063825/>`__. Notice that fewer results are found.
6161

6262
The class ``LoopStmt`` is a common superclass of all loops, including, in particular, ``for`` loops as in our example above. While different kinds of loops have different syntax, they all have a loop condition, which can be accessed through predicate ``getCondition``. We use the reflexive transitive closure operator ``*`` applied to the ``getAChildExpr`` predicate to express the requirement that ``expr`` should be nested inside the loop condition. In particular, it can be the loop condition itself.
6363

@@ -120,7 +120,7 @@ Now we rewrite our query to make use of these new classes:
120120
not expr.getAnOperand().isCompileTimeConstant()
121121
select expr
122122
123-
➤ `See the full query in the query console on LGTM.com <https://lgtm.com/query/1951710018/lang:java/>`__.
123+
➤ `See the full query in the query console on LGTM.com <https://lgtm.com/query/506868054626167462/>`__.
124124

125125
Further reading
126126
---------------

0 commit comments

Comments
 (0)