github / github/codeql

Java: `Annotation` has no source location for repeated annotation with implicit container

未關閉
#6,236 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
Java question
主要語言
CodeQL
星號
10.1k
分支
2.1k
平均合併
2 天 15 小時
30 天內合併 PR
141

描述

### Version
CodeQL CLI version: 2.5.7

### Description
When a [repeatable](https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/annotation/Repeatable.html) annotation is used multiple times on an element (therefore creating an implicit container annotation), the respective `Annotation` elements have no source location.
This prevents writing queries reasoning about the location of these annotations, and also renders them unusable for query result output. Similarly they are not displayed in the AST viewer of the CodeQL VSCode extension either.

### Reproduction steps
1. Create a Java database for the following source code
```java
import java.lang.annotation.*;

class RepeatableAnnotationTest {
@Repeatable(Markers.class)
@interface Marker { }

@interface Markers {
Marker[] value();
}

// These don't have source locations
@Marker
@Marker
String implicitContainer;

// Though explicitly using a container annotation works
// The @Marker annotations have source locations
@Markers({
@Marker,
@Marker
})
String explicitContainer;
}
```
2. Run this CodeQL query:
```ql
import java

from Annotation a
where a.getCompilationUnit().fromSource()
select a
```
:x: The annotations with implicit container annotation have no source location; they do not appear in the result set

Note however, that for the implicit container annotation itself the current behavior of not having a source location is expected and desired (to differentiate between implicit and explicit container annotations).

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。