github / github/codeql

Java: CompilationUnit elements in Module are `.class` files instead of `.java` files

Đang mở
#5,556 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
Java not security 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ả

There are two predicates for matching `CompilationUnit` to corresponding `Module`, [`Module.getACompilationUnit()`](https://codeql.github.com/codeql-standard-libraries/java/semmle/code/java/Modules.qll/predicate.Modules$Module$getACompilationUnit.0.html) and [`CompilationUnit.getModule()`](https://codeql.github.com/codeql-standard-libraries/java/semmle/code/java/CompilationUnit.qll/predicate.CompilationUnit$CompilationUnit$getModule.0.html) (both using the database predicate `cumodule(@file, @module)`).
The issue is that the reported compilation units appear to always be the `.class` files instead of the source `.java` files, even when the `module-info.java` file was part of the source.

For example the following query against OpenJDK has no results:
```ql
import java

from Module m, RefType t
where
t.fromSource()
and t.getCompilationUnit().getModule() = m
select m, t
```
[Query Console link](https://lgtm.com/query/2379112509629488370/)

However, if you manually try to match `.class` compilation units with `.java` compilation units, you will get the desired results:
```ql
import java

predicate areProbablySame(CompilationUnit classComp, CompilationUnit sourceComp) {
classComp.getPackage() = sourceComp.getPackage()
and classComp.getName() = sourceComp.getName()
}

from Module m, TopLevelType t, CompilationUnit classComp, CompilationUnit sourceComp
where
t.fromSource()
and sourceComp = t.getCompilationUnit()
and classComp = m.getACompilationUnit()
and areProbablySame(classComp, sourceComp)
select m, t, classComp.getRelativePath(), sourceComp.getRelativePath()
```
[Query Console link](https://lgtm.com/query/8137102133532318116/)

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.