github / github/codeql

Java: TypeAccess matches implicit access

Đang mở
#3,648 0 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 of the issue**
It appears `TypeAccess` matches implicit (?) access of types, and that even when it has to hold `fromSource()`. This is not documented, and even QL's built-in query [`java/unused-import`](https://github.com/github/codeql/blob/master/java/ql/src/Violations%20of%20Best%20Practice/legacy/UnnecessaryImport.ql) appears to not consider this.
This behavior renders `TypeAccess` useless for certain queries.

Try the query below on the demo projects on https://lgtm.com/query:
```ql
import java
import semmle.code.java.Conversions

from TypeAccess typeAccess, RefType type, Location location, int expectedLength, int startColumn, int actualLength
where
type = typeAccess.getType()
and location = typeAccess.getLocation()
and type = type.getErasure()
and not type instanceof GenericType
and not type.hasAnnotation()
and not typeAccess.hasQualifier()
and expectedLength = type.getName().length()
// Ignore type access spanning multiple lines
and location.getNumberOfLines() = 1
and startColumn = location.getStartColumn()
// + 1 because both are inclusive
and actualLength = location.getEndColumn() - startColumn + 1
and expectedLength != actualLength
select typeAccess, expectedLength, startColumn, actualLength
```

While it does match some actual explicit type access (where the type is fully qualified) it also matches enum constant declarations, complete lambda bodies and probably other non-explicit access.

Possibly related to #3644.

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.