github / github/codeql

Java: `Location.getFile().getAbsolutePath()` contains Windows drive letter for non-source classes

Đang mở
#5,712 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ả

### Version
CodeQL CLI version 2.5.0

### Description
For types which are not part of the source, `Location.getFile().getAbsolutePath()` returns a path which contains the Windows drive letter.
For tests which have the path (as part of the URL) in their expected output this therefore results in test failures on Windows.
For example if I run on Windows the test added by #5711 it fails due to the file URL mismatch.

However, it looks like there are no existing tests in this repository with non-source types in their exepcted output, and CodeQL CLI explicitly warns about this:
> Locations outside the test directory do not work well for regression tests.

Though it is still rather weird why the Windows drive letter is included in the first place.

### Example
Code QL query:
```ql
import java

from TypeObject t
select t, t.getLocation().getFile().getAbsolutePath()
```
Under Windows with the database being under `C:\...` the result is: C:/modules/java.base/java/lang/Object.class
Under Linux the result is: `/modules/java.base/java/lang/Object.class`

(Note: For some demo projects the path is `/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/rt.jar/java/lang/Object.class` ([Query Console link](https://lgtm.com/query/61030082203192419/)); I am not sure on what this depends and whether this could cause issues for other users as well)

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.