Top Description Inners Fields Constructors Methods
net.bytebuddy.build

public Class AccessControllerPlugin

extends ForElementMatcher
implements Factory
Class Inheritance
All Implemented Interfaces
net.bytebuddy.build.Plugin.Factory
Annotations
@Enhance
Imports
edu.umd.cs.findbugs.annotations.SuppressFBWarnings, net.bytebuddy.asm.AsmVisitorWrapper, net.bytebuddy.description.method.MethodDescription, net.bytebuddy.description.modifier.FieldManifestation, .Ownership, .Visibility, net.bytebuddy.description.type.TypeDefinition, .TypeDescription, net.bytebuddy.dynamic.ClassFileLocator, .DynamicType, net.bytebuddy.implementation.Implementation, net.bytebuddy.implementation.bytecode.ByteCodeAppender, .StackSize, net.bytebuddy.pool.TypePool, net.bytebuddy.utility.JavaType, .OpenedClassReader, net.bytebuddy.utility.nullability.MaybeNull, net.bytebuddy.jar.asm.Label, .MethodVisitor, .Opcodes, .Type, java.lang.annotation.*, java.security.Permission, .PrivilegedAction, .PrivilegedExceptionAction, java.util.Collections, .HashMap, .Map

A build tool plugin that instruments methods to dispatch to methods java.security.AccessController with equal signature. This can be useful to avoid using types from the java.security package which were deprecated for removal in Java 17. Annotated methods are dispatched to the JVM's access controller only if this type is available on the current VM, and if no system property is added and set to disable such dispatch. In the process, java.security.AccessControlContext is represented by Object.

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class
AccessControllerPlugin.AccessControlWrapper

An wrapper for a method that represents a method of AccessController which is weaved.

public static @interface
AccessControllerPlugin.Enhance

Indicates that the annotated method represents a pseudo implementation of java.security.AccessController which can be weaved to dispatch to the access controller if this is possible on the current VM and not explicitly disabled on the current VM via a system property.

protected abstract static class
AccessControllerPlugin.Initializer

A byte code appender to create an initializer segment that determines if the java.security.AccessController is available.

Field Summary

Modifier and TypeField and Description
private static final String
ACCESS_CONTROLLER

The binary name of java.security.AccessController.

private static final Object[]
EMPTY

An empty array to create frames without additional allocation.

private static final String
NAME

The name of the generated field.

private final String
property

The property to control if the access controller should be used even if available or null if such a property should not be available.

private static final Map<MethodDescription.SignatureToken, MethodDescription.SignatureToken>
SIGNATURES

A map to all signatures of java.security.AccessController from a signature that does not contain any types that are deprecated for removal.

Constructor Summary

AccessConstructor and Description
public
AccessControllerPlugin()

Creates a new plugin to weave access controller dispatches without a property to allow for disabling the access controller handling.

public
AccessControllerPlugin(String
The property to control if the access controller should be used even if available or null if such a property should not be available.
property
)

Creates a new plugin to weave access controller dispatches.

Method Summary

Modifier and TypeMethod and Description
public DynamicType.Builder<?>
apply(DynamicType.Builder<?>
The builder to use as a basis for the applied transformation.
builder
,
TypeDescription
The type being transformed.
typeDescription
,
ClassFileLocator
A class file locator that can locate other types in the scope of the project.
classFileLocator
)

Implements net.bytebuddy.build.Plugin.apply.

Applies this plugin.
public void
close()

Implements java.io.Closeable.close.

Closes this stream and releases any system resources associated with it.
public Plugin
make()

Implements net.bytebuddy.build.Plugin.Factory.make.

Returns a plugin that can be used for a transformation and which is subsequently closed.
Inherited from net.bytebuddy.build.Plugin.ForElementMatcher:
matches

Field Detail

ACCESS_CONTROLLERback to summary
private static final String ACCESS_CONTROLLER

The binary name of java.security.AccessController.

EMPTYback to summary
private static final Object[] EMPTY

An empty array to create frames without additional allocation.

NAMEback to summary
private static final String NAME

The name of the generated field.

propertyback to summary
private final String property

The property to control if the access controller should be used even if available or null if such a property should not be available.

Annotations
@MaybeNull
@ValueHandling:REVERSE_NULLABILITY
SIGNATURESback to summary
private static final Map<MethodDescription.SignatureToken, MethodDescription.SignatureToken> SIGNATURES

A map to all signatures of java.security.AccessController from a signature that does not contain any types that are deprecated for removal.

Constructor Detail

AccessControllerPluginback to summary
public AccessControllerPlugin()

Creates a new plugin to weave access controller dispatches without a property to allow for disabling the access controller handling.

AccessControllerPluginback to summary
public AccessControllerPlugin(String property)

Creates a new plugin to weave access controller dispatches.

Parameters
property:String

The property to control if the access controller should be used even if available or null if such a property should not be available.

Annotations
@Priority:2147483647

Method Detail

applyback to summary
public DynamicType.Builder<?> apply(DynamicType.Builder<?> builder, TypeDescription typeDescription, ClassFileLocator classFileLocator)

Implements net.bytebuddy.build.Plugin.apply.

Doc from net.bytebuddy.build.Plugin.apply.

Applies this plugin.

Parameters
builder:DynamicType.Builder<?>

The builder to use as a basis for the applied transformation.

typeDescription:TypeDescription

The type being transformed.

classFileLocator:ClassFileLocator

A class file locator that can locate other types in the scope of the project.

Returns:DynamicType.Builder<?>

The supplied builder with additional transformations registered.

Annotations
@SuppressFBWarnings:SBSC_USE_STRINGBUFFER_CONCATENATION
justification:Collision is unlikely and buffer overhead not justified.
closeback to summary
public void close()

Implements java.io.Closeable.close.

Doc from java.io.Closeable.close.

Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.

As noted in AutoCloseable#close(), cases where the close may fail require careful attention. It is strongly advised to relinquish the underlying resources and to internally mark the Closeable as closed, prior to throwing the IOException.

makeback to summary
public Plugin make()

Implements net.bytebuddy.build.Plugin.Factory.make.

Doc from net.bytebuddy.build.Plugin.Factory.make.

Returns a plugin that can be used for a transformation and which is subsequently closed.

Returns:Plugin

The plugin to use for type transformations.

net.bytebuddy.build back to summary

protected Class AccessControllerPlugin.AccessControlWrapper

extends Object
implements MethodVisitorWrapper
Class Inheritance
  • java.lang.Object
  • net.bytebuddy.build.AccessControllerPlugin.AccessControlWrapper
All Implemented Interfaces
net.bytebuddy.asm.AsmVisitorWrapper.ForDeclaredMethods.MethodVisitorWrapper
Annotations
@Enhance

An wrapper for a method that represents a method of AccessController which is weaved.

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class
AccessControllerPlugin.AccessControlWrapper.PrefixingMethodVisitor

A method visitor to implement a weaved method to dispatch to an java.security.AccessController, if available.

Field Summary

Modifier and TypeField and Description
private final String
name

The name of the field.

Constructor Summary

AccessConstructor and Description
protected
AccessControlWrapper(String
The name of the field.
name
)

Creates a new access control wrapper.

Method Summary

Modifier and TypeMethod and Description
public MethodVisitor
wrap(TypeDescription
The instrumented type.
instrumentedType
,
MethodDescription
The method that is currently being defined.
instrumentedMethod
,
MethodVisitor
The original field visitor that defines the given method.
methodVisitor
,
Implementation.Context
The implementation context to use.
implementationContext
,
TypePool
The type pool to use.
typePool
,
int
The ASM net.bytebuddy.jar.asm.ClassWriter reader flags to consider.
writerFlags
,
int
The ASM net.bytebuddy.jar.asm.ClassReader reader flags to consider.
readerFlags
)

Implements net.bytebuddy.asm.AsmVisitorWrapper.ForDeclaredMethods.MethodVisitorWrapper.wrap.

Wraps a method visitor.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

nameback to summary
private final String name

The name of the field.

Constructor Detail

AccessControlWrapperback to summary
protected AccessControlWrapper(String name)

Creates a new access control wrapper.

Parameters
name:String

The name of the field.

Method Detail

wrapback to summary
public MethodVisitor wrap(TypeDescription instrumentedType, MethodDescription instrumentedMethod, MethodVisitor methodVisitor, Implementation.Context implementationContext, TypePool typePool, int writerFlags, int readerFlags)

Implements net.bytebuddy.asm.AsmVisitorWrapper.ForDeclaredMethods.MethodVisitorWrapper.wrap.

Doc from net.bytebuddy.asm.AsmVisitorWrapper.ForDeclaredMethods.MethodVisitorWrapper.wrap.

Wraps a method visitor.

Parameters
instrumentedType:TypeDescription

The instrumented type.

instrumentedMethod:MethodDescription

The method that is currently being defined.

methodVisitor:MethodVisitor

The original field visitor that defines the given method.

implementationContext:Implementation.Context

The implementation context to use.

typePool:TypePool

The type pool to use.

writerFlags:int

The ASM net.bytebuddy.jar.asm.ClassWriter reader flags to consider.

readerFlags:int

The ASM net.bytebuddy.jar.asm.ClassReader reader flags to consider.

Returns:MethodVisitor

The wrapped method visitor.

net.bytebuddy.build back to summary

protected Class AccessControllerPlugin.AccessControlWrapper.PrefixingMethodVisitor

extends MethodVisitor
Class Inheritance

A method visitor to implement a weaved method to dispatch to an java.security.AccessController, if available.

Field Summary

Modifier and TypeField and Description
private final Implementation.Context.FrameGeneration
frameGeneration

Indicates the frame generation mode to apply.

private final TypeDescription
instrumentedType

The instrumented type.

private final String
name

The name of the field.

private final int
offset

The base offset of the weaved method.

private final MethodDescription.SignatureToken
token

The target signature of the method declared by the JVM access controller.

Inherited from net.bytebuddy.jar.asm.MethodVisitor:
apimv

Constructor Summary

AccessConstructor and Description
protected
PrefixingMethodVisitor(MethodVisitor
The method visitor to write to.
methodVisitor
,
TypeDescription
The instrumented type.
instrumentedType
,
MethodDescription.SignatureToken
The target signature of the method declared by the JVM access controller.
token
,
String
The name of the field.
name
,
int
The base offset of the instrumented method.
offset
,
Implementation.Context.FrameGeneration
Indicates the frame generation mode to apply.
frameGeneration
)

Creates a new prefixing method visitor.

Field Detail

frameGenerationback to summary
private final Implementation.Context.FrameGeneration frameGeneration

Indicates the frame generation mode to apply.

instrumentedTypeback to summary
private final TypeDescription instrumentedType

The instrumented type.

nameback to summary
private final String name

The name of the field.

offsetback to summary
private final int offset

The base offset of the weaved method.

tokenback to summary
private final MethodDescription.SignatureToken token

The target signature of the method declared by the JVM access controller.

Constructor Detail

PrefixingMethodVisitorback to summary
protected PrefixingMethodVisitor(MethodVisitor methodVisitor, TypeDescription instrumentedType, MethodDescription.SignatureToken token, String name, int offset, Implementation.Context.FrameGeneration frameGeneration)

Creates a new prefixing method visitor.

Parameters
methodVisitor:MethodVisitor

The method visitor to write to.

instrumentedType:TypeDescription

The instrumented type.

token:MethodDescription.SignatureToken

The target signature of the method declared by the JVM access controller.

name:String

The name of the field.

offset:int

The base offset of the instrumented method.

frameGeneration:Implementation.Context.FrameGeneration

Indicates the frame generation mode to apply.

Method Detail

visitCodeback to summary
public void visitCode()

Overrides net.bytebuddy.jar.asm.MethodVisitor.visitCode.

Doc from net.bytebuddy.jar.asm.MethodVisitor.visitCode.

Starts the visit of the method's code, if any (i.e. non abstract method).

Annotations
@Override
visitMaxsback to summary
public void visitMaxs(int stackSize, int localVariableLength)

Overrides net.bytebuddy.jar.asm.MethodVisitor.visitMaxs.

Doc from net.bytebuddy.jar.asm.MethodVisitor.visitMaxs.

Visits the maximum stack size and the maximum number of local variables of the method.

Parameters
stackSize:int

maximum stack size of the method.

localVariableLength:int

maximum number of local variables for the method.

Annotations
@Override
net.bytebuddy.build back to summary

public @Interface AccessControllerPlugin.Enhance

extends Annotation
Annotations
@Documented
@Target:METHOD
@Retention:RUNTIME

Indicates that the annotated method represents a pseudo implementation of java.security.AccessController which can be weaved to dispatch to the access controller if this is possible on the current VM and not explicitly disabled on the current VM via a system property.

Method Summary

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString
net.bytebuddy.build back to summary

protected abstract Class AccessControllerPlugin.Initializer

extends Object
implements ByteCodeAppender
Class Inheritance
All Implemented Interfaces
net.bytebuddy.implementation.bytecode.ByteCodeAppender
Known Direct Subclasses
net.bytebuddy.build.AccessControllerPlugin.Initializer.WithProperty, net.bytebuddy.build.AccessControllerPlugin.Initializer.WithoutProperty
Annotations
@Enhance

A byte code appender to create an initializer segment that determines if the java.security.AccessController is available.

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class
AccessControllerPlugin.Initializer.WithoutProperty

An initializer that always uses the access controller if it is available.

protected static class
AccessControllerPlugin.Initializer.WithProperty

An initializer that uses a property to determine if the access controller should be actually used even if it is available.

Field Summary

Modifier and TypeField and Description
private final TypeDescription
instrumentedType

The instrumented type.

private final String
name

The name of the field to determine the use of access controller dispatch.

Constructor Summary

AccessConstructor and Description
protected
Initializer(TypeDescription
The instrumented type.
instrumentedType
,
String
The name of the field to determine the use of access controller dispatch.
name
)

Creates a new initializer.

Method Summary

Modifier and TypeMethod and Description
public ByteCodeAppender.Size
apply(MethodVisitor
The method visitor to which the byte code appender writes its code to.
methodVisitor
,
Implementation.Context
The implementation context of the current type creation process.
implementationContext
,
MethodDescription
The method that is the target of the instrumentation.
instrumentedMethod
)

Implements net.bytebuddy.implementation.bytecode.ByteCodeAppender.apply.

Applies this byte code appender to a type creation process.
protected abstract int

Returns:

The size of the stack required to implement the implemented dispatch.
onAccessController
(MethodVisitor
The method visitor to dispatch to.
methodVisitor
)

Invoked to determine if the access controller should be used after the class was found.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

instrumentedTypeback to summary
private final TypeDescription instrumentedType

The instrumented type.

nameback to summary
private final String name

The name of the field to determine the use of access controller dispatch.

Constructor Detail

Initializerback to summary
protected Initializer(TypeDescription instrumentedType, String name)

Creates a new initializer.

Parameters
instrumentedType:TypeDescription

The instrumented type.

name:String

The name of the field to determine the use of access controller dispatch.

Method Detail

applyback to summary
public ByteCodeAppender.Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext, MethodDescription instrumentedMethod)

Implements net.bytebuddy.implementation.bytecode.ByteCodeAppender.apply.

Doc from net.bytebuddy.implementation.bytecode.ByteCodeAppender.apply.

Applies this byte code appender to a type creation process.

Parameters
methodVisitor:MethodVisitor

The method visitor to which the byte code appender writes its code to.

implementationContext:Implementation.Context

The implementation context of the current type creation process.

instrumentedMethod:MethodDescription

The method that is the target of the instrumentation.

Returns:ByteCodeAppender.Size

The required size for the applied byte code to run.

onAccessControllerback to summary
protected abstract int onAccessController(MethodVisitor methodVisitor)

Invoked to determine if the access controller should be used after the class was found.

Parameters
methodVisitor:MethodVisitor

The method visitor to dispatch to.

Returns:int

The size of the stack required to implement the implemented dispatch.

net.bytebuddy.build back to summary

protected Class AccessControllerPlugin.Initializer.WithoutProperty

extends Initializer
Class Inheritance
Annotations
@Enhance

An initializer that always uses the access controller if it is available.

Constructor Summary

AccessConstructor and Description
protected
WithoutProperty(TypeDescription
The instrumented type.
instrumentedType
,
String
The name of the field to determine the use of access controller dispatch.
name
)

Creates an initializer that always uses the access controller if it is available.

Method Summary

Modifier and TypeMethod and Description
protected int
onAccessController(MethodVisitor
The method visitor to dispatch to.
methodVisitor
)

Implements abstract net.bytebuddy.build.AccessControllerPlugin.Initializer.onAccessController.

Invoked to determine if the access controller should be used after the class was found.
Inherited from net.bytebuddy.build.AccessControllerPlugin.Initializer:
apply

Constructor Detail

WithoutPropertyback to summary
protected WithoutProperty(TypeDescription instrumentedType, String name)

Creates an initializer that always uses the access controller if it is available.

Parameters
instrumentedType:TypeDescription

The instrumented type.

name:String

The name of the field to determine the use of access controller dispatch.

Method Detail

onAccessControllerback to summary
protected int onAccessController(MethodVisitor methodVisitor)

Implements abstract net.bytebuddy.build.AccessControllerPlugin.Initializer.onAccessController.

Doc from net.bytebuddy.build.AccessControllerPlugin.Initializer.onAccessController.

Invoked to determine if the access controller should be used after the class was found.

Parameters
methodVisitor:MethodVisitor

The method visitor to dispatch to.

Returns:int

The size of the stack required to implement the implemented dispatch.

Annotations
@Override
net.bytebuddy.build back to summary

protected Class AccessControllerPlugin.Initializer.WithProperty

extends Initializer
Class Inheritance
Annotations
@Enhance

An initializer that uses a property to determine if the access controller should be actually used even if it is available.

Field Summary

Modifier and TypeField and Description
private final String
property

The name of the property.

Constructor Summary

AccessConstructor and Description
protected
WithProperty(TypeDescription
The instrumented type.
instrumentedType
,
String
The name of the field to determine the use of access controller dispatch.
name
,
String
The name of the property.
property
)

Creates an initializer that uses a property to determine if the access controller should be actually used even if it is available.

Method Summary

Modifier and TypeMethod and Description
protected int
onAccessController(MethodVisitor
The method visitor to dispatch to.
methodVisitor
)

Implements abstract net.bytebuddy.build.AccessControllerPlugin.Initializer.onAccessController.

Invoked to determine if the access controller should be used after the class was found.
Inherited from net.bytebuddy.build.AccessControllerPlugin.Initializer:
apply

Field Detail

propertyback to summary
private final String property

The name of the property.

Constructor Detail

WithPropertyback to summary
protected WithProperty(TypeDescription instrumentedType, String name, String property)

Creates an initializer that uses a property to determine if the access controller should be actually used even if it is available.

Parameters
instrumentedType:TypeDescription

The instrumented type.

name:String

The name of the field to determine the use of access controller dispatch.

property:String

The name of the property.

Method Detail

onAccessControllerback to summary
protected int onAccessController(MethodVisitor methodVisitor)

Implements abstract net.bytebuddy.build.AccessControllerPlugin.Initializer.onAccessController.

Doc from net.bytebuddy.build.AccessControllerPlugin.Initializer.onAccessController.

Invoked to determine if the access controller should be used after the class was found.

Parameters
methodVisitor:MethodVisitor

The method visitor to dispatch to.

Returns:int

The size of the stack required to implement the implemented dispatch.

Annotations
@Override