github / github/codeql

Java: Explicit `ArrayInit` containing annotation nested inside annotation as implicit array value is malformed

オープン
#6,276 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
Java question
主要言語
CodeQL
スター
10.1k
フォーク
2.1k
平均マージ
2日 15時間
マージ済み PR(30日)
141

説明

### Version
CodeQL CLI v2.5.7

### Description of the issue
An explicit `ArrayInit` containing one or more annotations, which is itself the value of an annotation being the single value for an array _without_ explicit `ArrayInit`, is erroneously reported as having no children.

This can be seen with one of the LGTM demo projects: [Query Console Link](https://lgtm.com/query/2136226172412136860/)

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

public class AnnTest2 {
@interface Ann { }

enum MyEnum {
A,
B
}

@interface Nested1 {
Ann ann();
Ann[] anns();
int[] ints();
MyEnum[] enumConstants();
}

@interface Nested2 {
// Also happens when this element is named `value` and annotation omits
// element name, e.g. `@Nested2(@Nested1(...))`
Nested1[] nested();
}

@Nested2(
// Type of `nested` is array, `@Nested1` is used here as single value without
// explicit ArrayInit
nested = @Nested1(
ann = @Ann,
// This ArrayInit is modelled erroneously (has no children)
anns = { @Ann },
// But these ArrayInits are correct
ints = { 1, 2 },
enumConstants = { MyEnum.A, MyEnum.B }
)
)
private String f;
}
```
2. Run the following CodeQL query
```ql
import java

from ArrayInit arrayInit
where arrayInit.getCompilationUnit().fromSource()
select arrayInit, arrayInit.getSize()
```
3. Have a look at the one `ArrayInit` result with size 0
:x: `anns = { @Ann }` is erroneously reported as having size 0

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。