-
CSR
-
Resolution: Approved
-
P4
-
None
-
behavioral
-
low
-
The old eager initialization may have been accidentally used as a feature; changing this behavior may change class loading order in user applications.
-
Java API
-
SE
Summary
Creating a VarHandle for a static field no longer triggers class initialization.
Problem
Previously, the static field declaring class initialization was done at VarHandle creation time which does not conform the specification that the class should only be initialized when the static field is accessed and the class has not been initialized.
Solution
Make MethodHandles::findStaticVarHandle
return a lazily-initialized VarHandle
that conform to the specifications; it only initializes the declaring class on operations that must require class initialization.
Specification
No change.
In the API specification of MethodHandles::findStaticVarHandle
:
If the returned VarHandle is operated on, the declaring class will be
initialized, if it has not already been initialized.
This new implementation conforms to the specification and also is performant than the old eager-initializing implementation.
- csr of
-
JDK-8291065 Creating a VarHandle for a static field triggers class initialization
- Resolved