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/annotations-in-java.rst
+7-5Lines changed: 7 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,11 @@
1
1
.. _annotations-in-java:
2
2
3
-
Annotations in Java
3
+
Annotations in Java and Kotlin
4
4
===================
5
5
6
-
CodeQL databases of Java projects contain information about all annotations attached to program elements.
6
+
CodeQL databases of Java/Kotlin projects contain information about all annotations attached to program elements.
7
+
8
+
.. include:: ../reusables/kotlin-beta-note.rst
7
9
8
10
About working with annotations
9
11
------------------------------
@@ -15,7 +17,7 @@ Annotations are represented by these CodeQL classes:
15
17
- The class ``AnnotationElement`` represents an annotation element, that is, a member of an annotation type.
16
18
- The class ``Annotation`` represents an annotation such as ``@Override``; annotation values can be accessed through member predicate ``getValue``.
17
19
18
-
For example, the Java standard library defines an annotation ``SuppressWarnings`` that instructs the compiler not to emit certain kinds of warnings:
20
+
For example, the Java/Kotlin standard library defines an annotation ``SuppressWarnings`` that instructs the compiler not to emit certain kinds of warnings:
19
21
20
22
.. code-block:: java
21
23
@@ -101,7 +103,7 @@ As a first step, let's write a query that finds all ``@Override`` annotations. A
101
103
where ann.getType().hasQualifiedName("java.lang", "Override")
102
104
select ann
103
105
104
-
As always, it is a good idea to try this query on a CodeQL database for a Java project to make sure it actually produces some results. On the earlier example, it should find the annotation on ``Sub1.m``. Next, we encapsulate the concept of an ``@Override`` annotation as a CodeQL class:
106
+
As always, it is a good idea to try this query on a CodeQL database for a Java/Kotlin project to make sure it actually produces some results. On the earlier example, it should find the annotation on ``Sub1.m``. Next, we encapsulate the concept of an ``@Override`` annotation as a CodeQL class:
105
107
106
108
::
107
109
@@ -185,7 +187,7 @@ For more information about the class ``Call``, see ":doc:`Navigating the call gr
185
187
Improvements
186
188
~~~~~~~~~~~~
187
189
188
-
The Java standard library provides another annotation type ``java.lang.SupressWarnings`` that can be used to suppress certain categories of warnings. In particular, it can be used to turn off warnings about calls to deprecated methods. Therefore, it makes sense to improve our query to ignore calls to deprecated methods from inside methods that are marked with ``@SuppressWarnings("deprecation")``.
190
+
The Java/Kotlin standard library provides another annotation type ``java.lang.SupressWarnings`` that can be used to suppress certain categories of warnings. In particular, it can be used to turn off warnings about calls to deprecated methods. Therefore, it makes sense to improve our query to ignore calls to deprecated methods from inside methods that are marked with ``@SuppressWarnings("deprecation")``.
189
191
190
192
For instance, consider this slightly updated example:
Copy file name to clipboardExpand all lines: docs/codeql/codeql-language-guides/codeql-for-java.rst
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,16 +32,16 @@ Experiment and learn how to write effective and efficient queries for CodeQL dat
32
32
33
33
- :doc:`Analyzing data flow in Java and Kotlin <analyzing-data-flow-in-java>`: You can use CodeQL to track the flow of data through a Java/Kotlin program to its use.
34
34
35
-
- :doc:`Java types <types-in-java>`: You can use CodeQL to find out information about data types used in Java code. This allows you to write queries to identify specific type-related issues.
35
+
- :doc:`Java and Kotlin types <types-in-java>`: You can use CodeQL to find out information about data types used in Java/Kotlin code. This allows you to write queries to identify specific type-related issues.
36
36
37
-
- :doc:`Overflow-prone comparisons in Java <overflow-prone-comparisons-in-java>`: You can use CodeQL to check for comparisons in Java code where one side of the comparison is prone to overflow.
37
+
- :doc:`Overflow-prone comparisons in Java and Kotlin <overflow-prone-comparisons-in-java>`: You can use CodeQL to check for comparisons in Java/Kotlin code where one side of the comparison is prone to overflow.
38
38
39
39
- :doc:`Navigating the call graph <navigating-the-call-graph>`: CodeQL has classes for identifying code that calls other code, and code that can be called from elsewhere. This allows you to find, for example, methods that are never used.
40
40
41
-
- :doc:`Annotations in Java <annotations-in-java>`: CodeQL databases of Java projects contain information about all annotations attached to program elements.
41
+
- :doc:`Annotations in Java and Kotlin <annotations-in-java>`: CodeQL databases of Java/Kotlin projects contain information about all annotations attached to program elements.
42
42
43
-
- :doc:`Javadoc <javadoc>`: You can use CodeQL to find errors in Javadoc comments in Java code.
43
+
- :doc:`Javadoc <javadoc>`: You can use CodeQL to find errors in Javadoc comments in Java/Kotlin code.
44
44
45
-
- :doc:`Working with source locations <working-with-source-locations>`: You can use the location of entities within Java code to look for potential errors. Locations allow you to deduce the presence, or absence, of white space which, in some cases, may indicate a problem.
45
+
- :doc:`Working with source locations <working-with-source-locations>`: You can use the location of entities within Java/Kotlin code to look for potential errors. Locations allow you to deduce the presence, or absence, of white space which, in some cases, may indicate a problem.
46
46
47
47
- :doc:`Abstract syntax tree classes for working with Java and Kotlin programs <abstract-syntax-tree-classes-for-working-with-java-programs>`: CodeQL has a large selection of classes for representing the abstract syntax tree of Java/Kotlin programs.
The Java analysis can be customized by adding library models (summaries, sinks and sources) in data extension files.
11
+
.. include:: ../reusables/kotlin-beta-note.rst
12
+
13
+
The Java/Kotlin analysis can be customized by adding library models (summaries, sinks and sources) in data extension files.
12
14
A model is a definition of a behavior of a library element, such as a method, that is used to improve the data flow analysis precision by identifying more results.
13
15
Most of the security related queries are taint tracking queries that try to find paths from a source of untrusted input to a sink that represents a vulnerability. Sources are the starting points of a taint tracking data flow analysis, and sinks are the end points of a taint tracking data flow analysis.
14
16
@@ -30,7 +32,7 @@ A data extension file for Java is a YAML file in the form:
30
32
31
33
Data extensions contribute to the extensible predicates defined in the CodeQL library. For more information on how to define data extensions and extensible predicates as well as how to wire them up, see the :ref:`data-extensions` documentation.
32
34
33
-
The CodeQL library for Java exposes the following extensible predicates:
35
+
The CodeQL library for Java/Kotlin exposes the following extensible predicates:
34
36
35
37
- **sourceModel**\(package, type, subtypes, name, signature, ext, output, kind, provenance). This is used for **source** models.
36
38
- **sinkModel**\(package, type, subtypes, name, signature, ext, input, kind, provenance). This is used for **sink** models.
@@ -48,7 +50,7 @@ Example: Taint sink in the **java.sql** package
48
50
49
51
In this example we will show how to model the argument of the **execute** method as a SQL injection sink.
50
52
This is the **execute** method in the **Statement** class, which is located in the **java.sql** package.
51
-
Note that this sink is already added to the CodeQL Java analysis.
53
+
Note that this sink is already added to the CodeQL Java/Kotlin analysis.
52
54
53
55
.. code-block:: java
54
56
@@ -89,7 +91,7 @@ Example: Taint source from the **java.net** package
Copy file name to clipboardExpand all lines: docs/codeql/codeql-language-guides/navigating-the-call-graph.rst
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ CodeQL has classes for identifying code that calls other code, and code that can
8
8
Call graph classes
9
9
------------------
10
10
11
-
The CodeQL library for Java provides two abstract classes for representing a program's call graph: ``Callable`` and ``Call``. The former is simply the common superclass of ``Method`` and ``Constructor``, the latter is a common superclass of ``MethodAccess``, ``ClassInstanceExpression``, ``ThisConstructorInvocationStmt`` and ``SuperConstructorInvocationStmt``. Simply put, a ``Callable`` is something that can be invoked, and a ``Call`` is something that invokes a ``Callable``.
11
+
The CodeQL library for Java/Kotlin provides two abstract classes for representing a program's call graph: ``Callable`` and ``Call``. The former is simply the common superclass of ``Method`` and ``Constructor``, the latter is a common superclass of ``MethodAccess``, ``ClassInstanceExpression``, ``ThisConstructorInvocationStmt`` and ``SuperConstructorInvocationStmt``. Simply put, a ``Callable`` is something that can be invoked, and a ``Call`` is something that invokes a ``Callable``.
12
12
13
13
For example, in the following program all callables and calls have been annotated with comments:
14
14
@@ -88,7 +88,7 @@ This simple query typically returns a large number of results.
88
88
89
89
We have to use ``polyCalls`` instead of ``calls`` here: we want to be reasonably sure that ``callee`` is not called, either directly or via overriding.
90
90
91
-
Running this query on a typical Java project results in lots of hits in the Java standard library. This makes sense, since no single client program uses every method of the standard library. More generally, we may want to exclude methods and constructors from compiled libraries. We can use the predicate ``fromSource`` to check whether a compilation unit is a source file, and refine our query:
91
+
Running this query on a typical Java/Kotlin project results in lots of hits in the Java/Kotlin standard library. This makes sense, since no single client program uses every method of the standard library. More generally, we may want to exclude methods and constructors from compiled libraries. We can use the predicate ``fromSource`` to check whether a compilation unit is a source file, and refine our query:
Copy file name to clipboardExpand all lines: docs/codeql/codeql-language-guides/types-in-java.rst
+4-2Lines changed: 4 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,11 @@
1
1
.. _types-in-java:
2
2
3
-
Types in Java
3
+
Types in Java and Kotlin
4
4
=============
5
5
6
-
You can use CodeQL to find out information about data types used in Java code. This allows you to write queries to identify specific type-related issues.
6
+
You can use CodeQL to find out information about data types used in Java/Kotlin code. This allows you to write queries to identify specific type-related issues.
Copy file name to clipboardExpand all lines: docs/codeql/codeql-language-guides/working-with-source-locations.rst
+4-2Lines changed: 4 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,9 @@
3
3
Working with source locations
4
4
=============================
5
5
6
-
You can use the location of entities within Java code to look for potential errors. Locations allow you to deduce the presence, or absence, of white space which, in some cases, may indicate a problem.
6
+
You can use the location of entities within Java/Kotlin code to look for potential errors. Locations allow you to deduce the presence, or absence, of white space which, in some cases, may indicate a problem.
7
+
8
+
.. include:: ../reusables/kotlin-beta-note.rst
7
9
8
10
About source locations
9
11
----------------------
@@ -175,7 +177,7 @@ Now we can extend our query to discard results where the outer and the inner exp
175
177
wsinner > wsouter
176
178
select outer, "Whitespace around nested operators contradicts precedence."
177
179
178
-
Notice that we again use ``getOp``, this time to determine whether two binary expressions have the same operator. Running our improved query now finds the Java standard library bug described in the Overview. It also flags up the following suspicious code in `Hadoop HBase <https://hbase.apache.org/>`__:
180
+
Notice that we again use ``getOp``, this time to determine whether two binary expressions have the same operator. Running our improved query now finds the Java/Kotlin standard library bug described in the Overview. It also flags up the following suspicious code in `Hadoop HBase <https://hbase.apache.org/>`__:
0 commit comments