Package org.objenesis.instantiator.basic
Class ProxyingInstantiator<T>
- java.lang.Object
-
- org.objenesis.instantiator.basic.ProxyingInstantiator<T>
-
- All Implemented Interfaces:
ObjectInstantiator<T>
@Instantiator(STANDARD) public class ProxyingInstantiator<T> extends java.lang.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 aVerifyErroris you do that. However, using-Xverify:noneshould make it work
-
-
Field Summary
Fields Modifier and Type Field Description private static byte[]CODEprivate static intCODE_ATTRIBUTE_LENGTHprivate static intCONSTANT_POOL_COUNTprivate static java.lang.StringCONSTRUCTOR_DESCprivate static java.lang.StringCONSTRUCTOR_NAMEprivate static intINDEX_CLASS_SUPERCLASSprivate static intINDEX_CLASS_THISprivate static intINDEX_UTF8_CLASSprivate static intINDEX_UTF8_CODE_ATTRIBUTEprivate static intINDEX_UTF8_CONSTRUCTOR_DESCprivate static intINDEX_UTF8_CONSTRUCTOR_NAMEprivate static intINDEX_UTF8_SUPERCLASSprivate java.lang.Class<? extends T>newTypeprivate static java.lang.StringPREFIXprivate static java.lang.StringSUFFIX
-
Constructor Summary
Constructors Constructor Description ProxyingInstantiator(java.lang.Class<T> type)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static java.lang.StringnameForSubclass(java.lang.Class<?> parent)TnewInstance()Returns a new instance of an object.private static byte[]writeExtendingClass(java.lang.Class<?> type, java.lang.String subclassName)Will generate the bytes for a class extending the type passed in parameter.
-
-
-
Field Detail
-
INDEX_CLASS_THIS
private static final int INDEX_CLASS_THIS
- See Also:
- Constant Field Values
-
INDEX_CLASS_SUPERCLASS
private static final int INDEX_CLASS_SUPERCLASS
- See Also:
- Constant Field Values
-
INDEX_UTF8_CONSTRUCTOR_NAME
private static final int INDEX_UTF8_CONSTRUCTOR_NAME
- See Also:
- Constant Field Values
-
INDEX_UTF8_CONSTRUCTOR_DESC
private static final int INDEX_UTF8_CONSTRUCTOR_DESC
- See Also:
- Constant Field Values
-
INDEX_UTF8_CODE_ATTRIBUTE
private static final int INDEX_UTF8_CODE_ATTRIBUTE
- See Also:
- Constant Field Values
-
INDEX_UTF8_CLASS
private static final int INDEX_UTF8_CLASS
- See Also:
- Constant Field Values
-
INDEX_UTF8_SUPERCLASS
private static final int INDEX_UTF8_SUPERCLASS
- See Also:
- Constant Field Values
-
CONSTANT_POOL_COUNT
private static final int CONSTANT_POOL_COUNT
- See Also:
- Constant Field Values
-
CODE
private static final byte[] CODE
-
CODE_ATTRIBUTE_LENGTH
private static final int CODE_ATTRIBUTE_LENGTH
-
PREFIX
private static final java.lang.String PREFIX
- See Also:
- Constant Field Values
-
SUFFIX
private static final java.lang.String SUFFIX
- See Also:
- Constant Field Values
-
CONSTRUCTOR_NAME
private static final java.lang.String CONSTRUCTOR_NAME
- See Also:
- Constant Field Values
-
CONSTRUCTOR_DESC
private static final java.lang.String CONSTRUCTOR_DESC
- See Also:
- Constant Field Values
-
newType
private final java.lang.Class<? extends T> newType
-
-
Constructor Detail
-
ProxyingInstantiator
public ProxyingInstantiator(java.lang.Class<T> type)
-
-
Method Detail
-
nameForSubclass
private static java.lang.String nameForSubclass(java.lang.Class<?> parent)
-
newInstance
public T newInstance()
Description copied from interface:ObjectInstantiatorReturns a new instance of an object. The returned object's class is defined by the implementation.- Specified by:
newInstancein interfaceObjectInstantiator<T>- Returns:
- A new instance of an object.
-
writeExtendingClass
private static byte[] writeExtendingClass(java.lang.Class<?> type, java.lang.String subclassName)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
-
-