Skip to content

Commit e990f1b

Browse files
authored
Merge pull request github#3546 from aschackmull/java/tutorial-bug-fix
Java: Fix bug in tutorial.
2 parents cf13992 + 6228e76 commit e990f1b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

docs/language/learn-ql/java/types-class-hierarchy.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ To identify these cases, we can create two CodeQL classes that represent, respec
114114
class CollectionToArrayCall extends MethodAccess {
115115
CollectionToArrayCall() {
116116
exists(CollectionToArray m |
117-
this.getMethod().getSourceDeclaration().overrides*(m)
117+
this.getMethod().getSourceDeclaration().overridesOrInstantiates*(m)
118118
)
119119
}
120120
@@ -124,7 +124,7 @@ To identify these cases, we can create two CodeQL classes that represent, respec
124124
}
125125
}
126126
127-
Notice the use of ``getSourceDeclaration`` and ``overrides`` in the constructor of ``CollectionToArrayCall``: we want to find calls to ``Collection.toArray`` and to any method that overrides it, as well as any parameterized instances of these methods. In our example above, for instance, the call ``l.toArray`` resolves to method ``toArray`` in the raw class ``ArrayList``. Its source declaration is method\ ``toArray`` in the generic class ``ArrayList``, which overrides ``AbstractCollection.toArray``, which in turn overrides ``Collection.toArray``.
127+
Notice the use of ``getSourceDeclaration`` and ``overridesOrInstantiates`` in the constructor of ``CollectionToArrayCall``: we want to find calls to ``Collection.toArray`` and to any method that overrides it, as well as any parameterized instances of these methods. In our example above, for instance, the call ``l.toArray`` resolves to method ``toArray`` in the raw class ``ArrayList``. Its source declaration is ``toArray`` in the generic class ``ArrayList<T>``, which overrides ``AbstractCollection<T>.toArray``, which in turn overrides ``Collection<T>.toArray``, which is an instantiation of ``Collection.toArray`` (since the type parameter ``T`` in the overridden method belongs to ``ArrayList`` and is an instantiation of the type parameter belonging to ``Collection``).
128128

129129
Using these new classes we can extend our query to exclude calls to ``toArray`` on an argument of type ``A[]`` which are then cast to ``A[]``:
130130

0 commit comments

Comments
 (0)