Skip to content

Java: Support CompileTimeConstantExpr for constant fields from compiled classes #8688

Open
@aschackmull

Description

@aschackmull

Discussed in #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:

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.

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions