Top Description Inners Fields Constructors Methods
org.easymock.bytebuddy.asm

public final Enum TypeConstantAdjustment

extends Enum<TypeConstantAdjustment>
implements AsmVisitorWrapper
Class Inheritance
All Implemented Interfaces
org.easymock.bytebuddy.asm.AsmVisitorWrapper
Imports
edu.umd.cs.findbugs.annotations.SuppressFBWarnings, org.easymock.bytebuddy.ClassFileVersion, org.easymock.bytebuddy.description.field.FieldDescription, .FieldList, org.easymock.bytebuddy.description.method.MethodList, org.easymock.bytebuddy.description.type.TypeDescription, org.easymock.bytebuddy.implementation.Implementation, org.easymock.bytebuddy.pool.TypePool, org.easymock.bytebuddy.utility.OpenedClassReader, org.easymock.bytebuddy.utility.nullability.MaybeNull, org.easymock.bytebuddy.jar.asm.*

This class visitor wrapper ensures that class files of a version previous to Java 5 do not store class entries in the generated class's constant pool. All found class instances are instead mapped as String values where the class constant is retrieved by a call to Class#forName(String).

Warning

This can lead to subtle bugs as classes that are not available yield a ClassNotFoundException instead of a NoClassDefFoundError. The former, checked exception could therefore be thrown even if the method that unsuccessfully loads a class does not declared the checked exception. Furthermore, Class constants are not cached as fields within the class as the Java compiler implemented class constants before Java 5. As a benefit for this limitation, the registered wrapper does not require any additional work by a ClassWriter or ClassReader, i.e. does not set any flags.

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class
TypeConstantAdjustment.TypeConstantDissolvingClassVisitor

A class visitor that checks a class file version for its support of storing class constants in the constant pool and remaps such constants on discovery if that is not the case.

Field Summary

Modifier and TypeField and Description
public static final TypeConstantAdjustment
INSTANCE

The singleton instance.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public int
mergeReader(int
The currently set flags. This value should be combined (e.g. flags | foo) into the value that is returned by this wrapper.
flags
)

Implements org.easymock.bytebuddy.asm.AsmVisitorWrapper.mergeReader.

Defines the flags that are provided to any ClassReader when reading a class if applicable.
public int
mergeWriter(int
The currently set flags. This value should be combined (e.g. flags | foo) into the value that is returned by this wrapper.
flags
)

Implements org.easymock.bytebuddy.asm.AsmVisitorWrapper.mergeWriter.

Defines the flags that are provided to any ClassWriter when writing a class.
public static TypeConstantAdjustment
public static TypeConstantAdjustment[]
public ClassVisitor
wrap(TypeDescription
The instrumented type.
instrumentedType
,
ClassVisitor
A ClassVisitor to become the new primary class visitor to which the created org.easymock.bytebuddy.dynamic.DynamicType is written to.
classVisitor
,
Implementation.Context
The implementation context of the current instrumentation.
implementationContext
,
TypePool
The type pool that was provided for the class creation.
typePool
,
FieldList<FieldDescription.InDefinedShape>
The instrumented type's fields.
fields
,
MethodList<?>
The instrumented type's methods non-ignored declared and virtually inherited methods.
methods
,
int writerFlags, int readerFlags)

Implements org.easymock.bytebuddy.asm.AsmVisitorWrapper.wrap.

Applies a ClassVisitorWrapper to the creation of a org.easymock.bytebuddy.dynamic.DynamicType.
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

INSTANCEback to summary
public static final TypeConstantAdjustment INSTANCE

The singleton instance.

Constructor Detail

TypeConstantAdjustmentback to summary
private TypeConstantAdjustment()

Method Detail

mergeReaderback to summary
public int mergeReader(int flags)

Implements org.easymock.bytebuddy.asm.AsmVisitorWrapper.mergeReader.

Doc from org.easymock.bytebuddy.asm.AsmVisitorWrapper.mergeReader.

Defines the flags that are provided to any ClassReader when reading a class if applicable. Typically, this gives opportunity to instruct ASM to expand or skip frames and to skip code and debug information. If no specific flags are required for applying this wrapper, the given value is to be returned.

Parameters
flags:int

The currently set flags. This value should be combined (e.g. flags | foo) into the value that is returned by this wrapper.

Returns:int

The flags to be provided to the ASM ClassReader.

mergeWriterback to summary
public int mergeWriter(int flags)

Implements org.easymock.bytebuddy.asm.AsmVisitorWrapper.mergeWriter.

Doc from org.easymock.bytebuddy.asm.AsmVisitorWrapper.mergeWriter.

Defines the flags that are provided to any ClassWriter when writing a class. Typically, this gives opportunity to instruct ASM to compute stack map frames or the size of the local variables array and the operand stack. If no specific flags are required for applying this wrapper, the given value is to be returned.

Parameters
flags:int

The currently set flags. This value should be combined (e.g. flags | foo) into the value that is returned by this wrapper.

Returns:int

The flags to be provided to the ASM ClassWriter.

valueOfback to summary
public static TypeConstantAdjustment valueOf(String name)
valuesback to summary
public static TypeConstantAdjustment[] values()
wrapback to summary
public ClassVisitor wrap(TypeDescription instrumentedType, ClassVisitor classVisitor, Implementation.Context implementationContext, TypePool typePool, FieldList<FieldDescription.InDefinedShape> fields, MethodList<?> methods, int writerFlags, int readerFlags)

Implements org.easymock.bytebuddy.asm.AsmVisitorWrapper.wrap.

Doc from org.easymock.bytebuddy.asm.AsmVisitorWrapper.wrap.

Applies a ClassVisitorWrapper to the creation of a org.easymock.bytebuddy.dynamic.DynamicType.

Parameters
instrumentedType:TypeDescription

The instrumented type.

classVisitor:ClassVisitor

A ClassVisitor to become the new primary class visitor to which the created org.easymock.bytebuddy.dynamic.DynamicType is written to.

implementationContext:Implementation.Context

The implementation context of the current instrumentation.

typePool:TypePool

The type pool that was provided for the class creation.

fields:FieldList<FieldDescription.InDefinedShape>

The instrumented type's fields.

methods:MethodList<?>

The instrumented type's methods non-ignored declared and virtually inherited methods.

writerFlags:int

The ASM org.easymock.bytebuddy.jar.asm.ClassWriter flags to consider.

readerFlags:int

The ASM org.easymock.bytebuddy.jar.asm.ClassReader flags to consider.

Returns:ClassVisitor

A new ClassVisitor that usually delegates to the ClassVisitor delivered in the argument.

org.easymock.bytebuddy.asm back to summary

protected Class TypeConstantAdjustment.TypeConstantDissolvingClassVisitor

extends ClassVisitor
Class Inheritance

A class visitor that checks a class file version for its support of storing class constants in the constant pool and remaps such constants on discovery if that is not the case.

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class

Field Summary

Modifier and TypeField and Description
private boolean
supportsTypeConstants

true if the class file version supports class constants in a constant pool.

Inherited from org.easymock.bytebuddy.jar.asm.ClassVisitor:
apicv

Constructor Summary

AccessConstructor and Description
protected
TypeConstantDissolvingClassVisitor(ClassVisitor
The underlying class visitor.
classVisitor
)

Creates a new type constant dissolving class visitor.

Method Summary

Modifier and TypeMethod and Description
public void
visit(int
the class version. The minor version is stored in the 16 most significant bits, and the major version in the 16 least significant bits.
version
,
int
the class's access flags (see Opcodes). This parameter also indicates if the class is deprecated Opcodes#ACC_DEPRECATED or a record Opcodes#ACC_RECORD.
modifiers
,
String
the internal name of the class (see Type#getInternalName()).
name
,
String
the signature of this class. May be null if the class is not a generic one, and does not extend or implement generic classes or interfaces.
signature
,
String
the internal of name of the super class (see Type#getInternalName()). For interfaces, the super class is Object. May be null, but only for the Object class.
superClassName
,
String[]
the internal names of the class's interfaces (see Type#getInternalName()). May be null.
interfaceName
)

Overrides org.easymock.bytebuddy.jar.asm.ClassVisitor.visit.

Visits the header of the class.
public MethodVisitor
visitMethod(int
the method's access flags (see Opcodes). This parameter also indicates if the method is synthetic and/or deprecated.
modifiers
,
String
the method's name.
name
,
String
the method's descriptor (see Type).
descriptor
,
String
the method's signature. May be null if the method parameters, return type and exceptions do not use generic types.
signature
,
String[]
the internal names of the method's exception classes (see Type#getInternalName()). May be null.
exception
)

Overrides org.easymock.bytebuddy.jar.asm.ClassVisitor.visitMethod.

Visits a method of the class.
Inherited from org.easymock.bytebuddy.jar.asm.ClassVisitor:
getDelegatevisitAnnotationvisitAttributevisitEndvisitFieldvisitInnerClassvisitModulevisitNestHostvisitNestMembervisitOuterClassvisitPermittedSubclassvisitRecordComponentvisitSourcevisitTypeAnnotation

Field Detail

supportsTypeConstantsback to summary
private boolean supportsTypeConstants

true if the class file version supports class constants in a constant pool.

Constructor Detail

TypeConstantDissolvingClassVisitorback to summary
protected TypeConstantDissolvingClassVisitor(ClassVisitor classVisitor)

Creates a new type constant dissolving class visitor.

Parameters
classVisitor:ClassVisitor

The underlying class visitor.

Method Detail

visitback to summary
public void visit(int version, int modifiers, String name, String signature, String superClassName, String[] interfaceName)

Overrides org.easymock.bytebuddy.jar.asm.ClassVisitor.visit.

Doc from org.easymock.bytebuddy.jar.asm.ClassVisitor.visit.

Visits the header of the class.

Parameters
version:int

the class version. The minor version is stored in the 16 most significant bits, and the major version in the 16 least significant bits.

modifiers:int

the class's access flags (see Opcodes). This parameter also indicates if the class is deprecated Opcodes#ACC_DEPRECATED or a record Opcodes#ACC_RECORD.

name:String

the internal name of the class (see Type#getInternalName()).

signature:String

the signature of this class. May be null if the class is not a generic one, and does not extend or implement generic classes or interfaces.

superClassName:String

the internal of name of the super class (see Type#getInternalName()). For interfaces, the super class is Object. May be null, but only for the Object class.

interfaceName:String[]

the internal names of the class's interfaces (see Type#getInternalName()). May be null.

Annotations
@Override
visitMethodback to summary
public MethodVisitor visitMethod(int modifiers, String name, String descriptor, String signature, String[] exception)

Overrides org.easymock.bytebuddy.jar.asm.ClassVisitor.visitMethod.

Doc from org.easymock.bytebuddy.jar.asm.ClassVisitor.visitMethod.

Visits a method of the class. This method must return a new MethodVisitor instance (or null) each time it is called, i.e., it should not return a previously returned visitor.

Parameters
modifiers:int

the method's access flags (see Opcodes). This parameter also indicates if the method is synthetic and/or deprecated.

name:String

the method's name.

descriptor:String

the method's descriptor (see Type).

signature:String

the method's signature. May be null if the method parameters, return type and exceptions do not use generic types.

exception:String[]

the internal names of the method's exception classes (see Type#getInternalName()). May be null.

Returns:MethodVisitor

an object to visit the byte code of the method, or null if this class visitor is not interested in visiting the code of this method.

Annotations
@Override
@MaybeNull
org.easymock.bytebuddy.asm back to summary

protected Class TypeConstantAdjustment.TypeConstantDissolvingClassVisitor.TypeConstantDissolvingMethodVisitor

extends MethodVisitor
Class Inheritance

A method visitor that remaps class constants to invocations of Class#forName(String).

Field Summary

Modifier and TypeField and Description
private static final String
DESCRIPTOR

The descriptor of the forName method.

private static final String
FOR_NAME

The forName method name.

private static final String
JAVA_LANG_CLASS

The internal name of the Class class.

Inherited from org.easymock.bytebuddy.jar.asm.MethodVisitor:
apimv

Constructor Summary

AccessConstructor and Description
protected
TypeConstantDissolvingMethodVisitor(MethodVisitor
The underlying method visitor.
methodVisitor
)

Creates a new type constant dissolving method visitor.

Method Summary

Modifier and TypeMethod and Description
public void
visitLdcInsn(Object
the constant to be loaded on the stack. This parameter must be a non null Integer, a Float, a Long, a Double, a String, a Type of OBJECT or ARRAY sort for .class constants, for classes whose version is 49, a Type of METHOD sort for MethodType, a Handle for MethodHandle constants, for classes whose version is 51 or a ConstantDynamic for a constant dynamic for classes whose version is 55.
value
)

Overrides org.easymock.bytebuddy.jar.asm.MethodVisitor.visitLdcInsn.

Visits a LDC instruction.
Inherited from org.easymock.bytebuddy.jar.asm.MethodVisitor:
getDelegatevisitAnnotableParameterCountvisitAnnotationvisitAnnotationDefaultvisitAttributevisitCodevisitEndvisitFieldInsnvisitFramevisitIincInsnvisitInsnvisitInsnAnnotationvisitIntInsnvisitInvokeDynamicInsnvisitJumpInsnvisitLabelvisitLineNumbervisitLocalVariablevisitLocalVariableAnnotationvisitLookupSwitchInsnvisitMaxsvisitMethodInsnvisitMethodInsnvisitMultiANewArrayInsnvisitParametervisitParameterAnnotationvisitTableSwitchInsnvisitTryCatchAnnotationvisitTryCatchBlockvisitTypeAnnotationvisitTypeInsnvisitVarInsn

Field Detail

DESCRIPTORback to summary
private static final String DESCRIPTOR

The descriptor of the forName method.

FOR_NAMEback to summary
private static final String FOR_NAME

The forName method name.

JAVA_LANG_CLASSback to summary
private static final String JAVA_LANG_CLASS

The internal name of the Class class.

Constructor Detail

TypeConstantDissolvingMethodVisitorback to summary
protected TypeConstantDissolvingMethodVisitor(MethodVisitor methodVisitor)

Creates a new type constant dissolving method visitor.

Parameters
methodVisitor:MethodVisitor

The underlying method visitor.

Method Detail

visitLdcInsnback to summary
public void visitLdcInsn(Object value)

Overrides org.easymock.bytebuddy.jar.asm.MethodVisitor.visitLdcInsn.

Doc from org.easymock.bytebuddy.jar.asm.MethodVisitor.visitLdcInsn.

Visits a LDC instruction. Note that new constant types may be added in future versions of the Java Virtual Machine. To easily detect new constant types, implementations of this method should check for unexpected constant types, like this:

if (cst instanceof Integer) {
    // ...
} else if (cst instanceof Float) {
    // ...
} else if (cst instanceof Long) {
    // ...
} else if (cst instanceof Double) {
    // ...
} else if (cst instanceof String) {
    // ...
} else if (cst instanceof Type) {
    int sort = ((Type) cst).getSort();
    if (sort == Type.OBJECT) {
        // ...
    } else if (sort == Type.ARRAY) {
        // ...
    } else if (sort == Type.METHOD) {
        // ...
    } else {
        // throw an exception
    }
} else if (cst instanceof Handle) {
    // ...
} else if (cst instanceof ConstantDynamic) {
    // ...
} else {
    // throw an exception
}
Parameters
value:Object

the constant to be loaded on the stack. This parameter must be a non null Integer, a Float, a Long, a Double, a String, a Type of OBJECT or ARRAY sort for .class constants, for classes whose version is 49, a Type of METHOD sort for MethodType, a Handle for MethodHandle constants, for classes whose version is 51 or a ConstantDynamic for a constant dynamic for classes whose version is 55.

Annotations
@Override
@SuppressFBWarnings:SF_SWITCH_NO_DEFAULT
justification:Fall through to default case is intentional.