github / github/codeql

Java: `getLocation()` result contains same location twice for some elements

Đang mở
#7,310 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
Java question
Ngôn ngữ chính
CodeQL
Star
10.1k
Fork
2.1k
Merge trung bình
2 ngày 15 giờ
Pull request đã merge (30 ngày)
141

Mô tả

### Description
For some elements the result of `getLocation()` contains the (seemingly) same location twice. Absolute file path, line and column numbers all seem to match, but for some reason these are two separate `Location` entities.

(Note that there are also other cases where `getLocation()` has more than one result, but at different locations, see #5734 and #7309. However, the issue described here appears regardless of whether the project has multiple modules / sub-projects or not.)

### Example query
```ql
import java

from Top t
where
// Only consider results in source code
t.getLocation().getFile().getExtension() = "java"
// And there are at least two different Location elements
and exists(Location location, Location otherLocation |
location = t.getLocation()
and otherLocation = t.getLocation()
and location != otherLocation
|
// Only consider if in same file; ignore if file is present multiple times with different paths, see #5734
location.getFile().getAbsolutePath() = otherLocation.getFile().getAbsolutePath()
)
// Only consider if all locations are exactly the same
and count(t.getLocation().toString()) = 1
select t, t.getLocation()
```
[Query Console link](https://lgtm.com/query/3705892995164895283/)

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.