Package net.bytebuddy.implementation
Class LoadedTypeInitializer.ForStaticField
java.lang.Object
net.bytebuddy.implementation.LoadedTypeInitializer.ForStaticField
- All Implemented Interfaces:
Serializable
,LoadedTypeInitializer
- Enclosing interface:
- LoadedTypeInitializer
@Enhance
public static class LoadedTypeInitializer.ForStaticField
extends Object
implements LoadedTypeInitializer, Serializable
A type initializer for setting a value for a static field.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface net.bytebuddy.implementation.LoadedTypeInitializer
LoadedTypeInitializer.Compound, LoadedTypeInitializer.ForStaticField, LoadedTypeInitializer.NoOp
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Object
The access control context to use for loading classes ornull
if the access controller is not available on the current VM.private final String
The name of the field.private static final long
This class's serial version UID.private final Object
The value of the field. -
Constructor Summary
ConstructorsConstructorDescriptionForStaticField
(String fieldName, Object value) Creates a newLoadedTypeInitializer
for setting a static field. -
Method Summary
Modifier and TypeMethodDescriptionprivate static <T> T
doPrivileged
(PrivilegedAction<T> action, Object context) A proxy forjava.security.AccessController#doPrivileged
that is activated if available.private static Object
A proxy forjava.security.AccessController#getContext
that is activated if available.boolean
isAlive()
Indicates if this initializer is alive and needs to be invoked.void
Callback that is invoked on the creation of an instrumented type.private Object
Resolves this instance after deserialization to assure the access control context is set.
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDThis class's serial version UID.- See Also:
-
fieldName
The name of the field. -
value
The value of the field. -
accessControlContext
The access control context to use for loading classes ornull
if the access controller is not available on the current VM.
-
-
Constructor Details
-
ForStaticField
Creates a newLoadedTypeInitializer
for setting a static field.- Parameters:
fieldName
- the name of the field.value
- The value to be set.
-
-
Method Details
-
getContext
A proxy forjava.security.AccessController#getContext
that is activated if available.- Returns:
- The current access control context or
null
if the current VM does not support it.
-
doPrivileged
A proxy forjava.security.AccessController#doPrivileged
that is activated if available.- Type Parameters:
T
- The type of the action's resolved value.- Parameters:
action
- The action to execute from a privileged context.context
- The access control context ornull
if the current VM does not support it.- Returns:
- The action's resolved value.
-
readResolve
Resolves this instance after deserialization to assure the access control context is set.- Returns:
- A resolved instance of this instance that includes an appropriate access control context.
-
onLoad
Callback that is invoked on the creation of an instrumented type. If the loaded type initializer is alive, this method should be implemented empty instead of throwing an exception.- Specified by:
onLoad
in interfaceLoadedTypeInitializer
- Parameters:
type
- The manifestation of the instrumented type.
-
isAlive
public boolean isAlive()Indicates if this initializer is alive and needs to be invoked. This is only meant as a mark. A loaded type initializer that is not alive might still be called and must therefore not throw an exception but rather provide an empty implementation.- Specified by:
isAlive
in interfaceLoadedTypeInitializer
- Returns:
true
if this initializer is alive.
-