github / github/codeql

Java: Support `CompileTimeConstantExpr` for constant fields from compiled classes

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

描述

### Discussed in https://github.com/github/codeql/discussions/8650

Originally posted by **Marcono1234** April 2, 2022
When compiled classes have constant fields, source code referencing them uses the constant value. A simple example for this is the following:
```java
class ConstantTest {
static final int VALUE = Integer.MAX_VALUE;
}
```
Compiling this class and inspecting it with `javap -v` shows that the value of `Integer.MAX_VALUE`, that is 2147483647, has been stored in the class file (instead of performing a field read). This is also explicitly mentioned in [JLS 17 §13.4.9](https://docs.oracle.com/javase/specs/jls/se17/html/jls-13.html#jls-13.4.9).

Currently CodeQL's `CompileTimeConstantExpr` does not support this; I assume because the information is missing from the database. Would it be possible to store this information in the database during extraction?

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

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

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