You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This code is semantically incorrect since enum constructors can't be used directly and enum constants (and static final constants in general) can't be assigned twice.
The text was updated successfully, but these errors were encountered:
In general, static fields that are initialized with lambdas are initialized in static initializer blocks instead of in fields declarations themselves (which is usually just possible). While this does not necessary produce incorrect code outside of enums, it would be better to move all field initializers to field declarations where possible.
It seems that fields are initialized in static blocks once they reference local variables. In most situations this is not the case. In case of lambdas, the parameters of the lambdas are counted as local variables referenced by the field initialization and the field initializer is not moved to the field declaration.
To fix the issue, during moving field initializers to declarations the searching for local variable references should stop once the SearchLocalVariableReferenceVisitor enters a lambda expression and continue once it exits that expression.
Consider the following enum:
Compiling this with
javac
and decompiling this withjd-core
produces incorrect java code:This code is semantically incorrect since enum constructors can't be used directly and enum constants (and
static final
constants in general) can't be assigned twice.The text was updated successfully, but these errors were encountered: