github / github/codeql

Shadowing happens when overriding method

オープン
#15,525 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る
Java question
主要言語
CodeQL
スター
10.1k
フォーク
2.1k
平均マージ
2日 15時間
マージ済み PR(30日)
141

説明

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();
}
}
```

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

MyCallable.qll、Query.ql、および提供された GenericsClass Java 例を使って問題を再現する。MyCallable の import がある場合とない場合でクエリ結果を比較し、その後、オーバーライドされている hasQualifiedName および isDeclaredIn 述語を調べる。shadowing の動作を理解し、どちらの場合でもクエリが意図したとおりに動作すれば完了とする。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
java
領域
devtools
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。