github / github/codeql

Shadowing happens when overriding method

Offen
#15,525 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Java question
Vorherrschende Sprache
CodeQL
Sterne
10.1k
Forks
2.1k
Ø Merge
2 T. 15 Std.
Gemergte PRs (30 T.)
141

Beschreibung

Consider the following example:

##### MyCallable.qll
```codeql
import java

class CallableByErasure extends Callable {
override predicate hasQualifiedName(string package, string type, string name) {
this.isDeclaredIn(package, type) and this.hasName(name)
}

predicate isDeclaredIn(string package, string type) {
this.getDeclaringType().getErasure().(RefType).hasQualifiedName(package, type)
}
}

```
##### Query.ql
```codeql
import java
// import MyCallable

from Call c
where c.getCallee().hasQualifiedName("java.util", "Set", "iterator")
select c

```

The query correctly finds one instance (see test case below).
If I uncomment `import MyCallable` however, then the query does not return anything. Is this expected behaviour? How do I prevent this from happening?

This is the test case I used:
```java
import java.util.HashSet;
import java.util.Set;

class GenericsClass {
public void foo() {
Set set = new HashSet();
set.iterator();
}
}
```

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.