github / github/codeql

Java: Add predicates for `AnnotationElement` default value

Đang mở
#6,275 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**
The elements of annotation interfaces can have default values, for example:
```java
@interface MyInterface {
String value() default "test";
}
```

However, currently `AnnotationElement` does not provide any predicates for detecting such default values. It appears they do not even exist in the database unless an annotation of the declaring annotation type is used somewhere. And even then they only exist as expression without source location.
(Note that the `Annotation` predicates always include the default values in their results.)

It would be good to add the following predicates
- `predicate hasDefaultValue()`
Note that the predicate `isDefault()` does not work for this because an annotation element with default value is not a `default` method, in fact it is an abstract method with the `AnnotationDefault` attribute in bytecode (see [JVM spec 16 §4.7.22](https://docs.oracle.com/javase/specs/jvms/se16/html/jvms-4.html#jvms-4.7.22)).
- `Expr getDefaultValue()`
Note that even though an `AnnotationElement` is effectively a method (see #5399), the default value should probably not be modeled as result of a synthetic `return` in the method body, but be stored directly in the database. As pointed out above, an annotation element with default value is not a regular `default` method, therefore modeling it as such would be irritating (e.g. it would have to be modeled as `abstract` method whose `getBody()` has a result).
Ideally this predicate would also work for annotations declared in third party code, not being part of the source, in case that is possible.

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.