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.
| Modifier and Type | Class 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. |
| Modifier and Type | Field and Description |
|---|---|
| public static final TypeConstantAdjustment | INSTANCE
The singleton instance. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public int | mergeReader(int
The currently set flags. This value should be combined (e.g. flags)flags | foo) into the value that is returned by this wrapper.Implements net. ClassReader when reading a class if applicable.
|
| public int | mergeWriter(int
The currently set flags. This value should be combined (e.g. flags)flags | foo) into the value that is returned by this wrapper.Implements net. ClassWriter when writing a class.
|
| public static TypeConstantAdjustment | |
| public static TypeConstantAdjustment[] | |
| public ClassVisitor | wrap(TypeDescription
The instrumented type. instrumentedType, ClassVisitor A classVisitor, Implementation.ClassVisitor to become the new primary class visitor to which the created
net. is written to.The implementation context of the current instrumentation. implementationContext,The type pool that was provided for the class creation. typePool, FieldList<FieldDescription.The instrumented type's fields. fields,The instrumented type's methods non-ignored declared and virtually inherited methods. methods, int The ASM writerFlags, int net. flags to consider.The ASM readerFlags)net. flags to consider.Implements net. ClassVisitorWrapper to the creation of a net..
|
| INSTANCE | back to summary |
|---|---|
| public static final TypeConstantAdjustment INSTANCE The singleton instance. | |
| TypeConstantAdjustment | back to summary |
|---|---|
| private TypeConstantAdjustment() | |
| mergeReader | back to summary |
|---|---|
| public int mergeReader(int flags) Implements net. Doc from net. Defines the flags that are provided to any
| |
| mergeWriter | back to summary |
|---|---|
| public int mergeWriter(int flags) Implements net. Doc from net. Defines the flags that are provided to any
| |
| valueOf | back to summary |
|---|---|
| public static TypeConstantAdjustment valueOf(String name) | |
| values | back to summary |
|---|---|
| public static TypeConstantAdjustment[] values() | |
| wrap | back to summary |
|---|---|
| public ClassVisitor wrap(TypeDescription instrumentedType, ClassVisitor classVisitor, Implementation. Implements net. Doc from net. Applies a
| |
| Modifier and Type | Class and Description |
|---|---|
| protected static class | TypeConstantAdjustment.TypeConstantDissolvingClassVisitor.TypeConstantDissolvingMethodVisitor
A method visitor that remaps class constants to invocations of |
| Modifier and Type | Field and Description |
|---|---|
| private boolean | supportsTypeConstants
|
| Access | Constructor and Description |
|---|---|
| protected | TypeConstantDissolvingClassVisitor(ClassVisitor
The underlying class visitor. classVisitor)Creates a new type constant dissolving class visitor. |
| Modifier and Type | Method 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 modifiers, String Opcodes). This parameter also indicates if
the class is deprecated Opcodes#ACC_DEPRECATED or a record Opcodes#ACC_RECORD.the internal name of the class (see name, String Type#getInternalName()).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 superClassName, String[] Type#getInternalName()).
For interfaces, the super class is Object. May be null, but only for the
Object class.the internal names of the class's interfaces (see interfaceName)Type#getInternalName()). May be null.Overrides net. |
| public MethodVisitor | visitMethod(int
the method's access flags (see modifiers, String Opcodes). This parameter also indicates if
the method is synthetic and/or deprecated.the method's name. name, String the method's descriptor (see descriptor, String Type).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 exception)
Visits a method of the class.
Type#getInternalName()). May be null. |
| supportsTypeConstants | back to summary |
|---|---|
| private boolean supportsTypeConstants
| |
| TypeConstantDissolvingClassVisitor | back to summary |
|---|---|
| protected TypeConstantDissolvingClassVisitor(ClassVisitor classVisitor) Creates a new type constant dissolving class visitor.
| |
| visit | back to summary |
|---|---|
| public void visit(int version, int modifiers, String name, String signature, String superClassName, String[] interfaceName) Overrides net. Doc from net. Visits the header of the class.
| |
| visitMethod | back to summary |
|---|---|
| public MethodVisitor visitMethod(int modifiers, String name, String descriptor, String signature, String[] exception) Overrides net. Doc from net. Visits a method of the class. This method must return a new
| |
Class#forName(String).
| Modifier and Type | Field and Description |
|---|---|
| private static final String | DESCRIPTOR
The descriptor of the |
| private static final String | FOR_NAME
The |
| private static final String | JAVA_LANG_CLASS
The internal name of the |
| Access | Constructor and Description |
|---|---|
| protected | TypeConstantDissolvingMethodVisitor(MethodVisitor
The underlying method visitor. methodVisitor)Creates a new type constant dissolving method visitor. |
| Modifier and Type | Method and Description |
|---|---|
| public void | visitLdcInsn(Object
the constant to be loaded on the stack. This parameter must be a non null value)
Visits a LDC instruction.
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. |
| DESCRIPTOR | back to summary |
|---|---|
| private static final String DESCRIPTOR The descriptor of the | |
| FOR_NAME | back to summary |
|---|---|
| private static final String FOR_NAME The | |
| JAVA_LANG_CLASS | back to summary |
|---|---|
| private static final String JAVA_LANG_CLASS The internal name of the | |
| TypeConstantDissolvingMethodVisitor | back to summary |
|---|---|
| protected TypeConstantDissolvingMethodVisitor(MethodVisitor methodVisitor) Creates a new type constant dissolving method visitor.
| |
| visitLdcInsn | back to summary |
|---|---|
| public void visitLdcInsn(Object value) Overrides net. Doc from net. 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
}
| |