Class ProxyingInstantiator<T>
java.lang.Object
org.objenesis.instantiator.exotic.ProxyingInstantiator<T>
- All Implemented Interfaces:
ObjectInstantiator<T>
@Instantiator(STANDARD)
public class ProxyingInstantiator<T>
extends Object
implements ObjectInstantiator<T>
This instantiator creates a class by dynamically extending it. It will skip the call to the parent constructor
in the bytecode. So that the constructor is indeed not called but you however instantiate a child class, not
the actual class. The class loader will normally throw a
VerifyError
is you do that. However, using
-Xverify:none
should make it work-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final byte[]
private static final int
private static final int
private static final String
private static final String
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final String
private static final String
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static String
nameForSubclass
(Class<?> parent) Returns a new instance of an object.private static byte[]
writeExtendingClass
(Class<?> type, String subclassName) Will generate the bytes for a class extending the type passed in parameter.
-
Field Details
-
INDEX_CLASS_THIS
private static final int INDEX_CLASS_THIS- See Also:
-
INDEX_CLASS_SUPERCLASS
private static final int INDEX_CLASS_SUPERCLASS- See Also:
-
INDEX_UTF8_CONSTRUCTOR_NAME
private static final int INDEX_UTF8_CONSTRUCTOR_NAME- See Also:
-
INDEX_UTF8_CONSTRUCTOR_DESC
private static final int INDEX_UTF8_CONSTRUCTOR_DESC- See Also:
-
INDEX_UTF8_CODE_ATTRIBUTE
private static final int INDEX_UTF8_CODE_ATTRIBUTE- See Also:
-
INDEX_UTF8_CLASS
private static final int INDEX_UTF8_CLASS- See Also:
-
INDEX_UTF8_SUPERCLASS
private static final int INDEX_UTF8_SUPERCLASS- See Also:
-
CONSTANT_POOL_COUNT
private static final int CONSTANT_POOL_COUNT- See Also:
-
CODE
private static final byte[] CODE -
CODE_ATTRIBUTE_LENGTH
private static final int CODE_ATTRIBUTE_LENGTH -
PREFIX
- See Also:
-
SUFFIX
- See Also:
-
CONSTRUCTOR_NAME
- See Also:
-
CONSTRUCTOR_DESC
- See Also:
-
newType
-
-
Constructor Details
-
ProxyingInstantiator
-
-
Method Details
-
nameForSubclass
-
newInstance
Description copied from interface:ObjectInstantiator
Returns a new instance of an object. The returned object's class is defined by the implementation.- Specified by:
newInstance
in interfaceObjectInstantiator<T>
- Returns:
- A new instance of an object.
-
writeExtendingClass
Will generate the bytes for a class extending the type passed in parameter. This class will only have an empty default constructor- Parameters:
type
- type to extendsubclassName
- name to give to the subclass- Returns:
- the byte for the class
- Throws:
ObjenesisException
- is something goes wrong
-