Package org.objenesis.instantiator.sun
Class MagicInstantiator<T>
- java.lang.Object
-
- org.objenesis.instantiator.sun.MagicInstantiator<T>
-
- All Implemented Interfaces:
ObjectInstantiator<T>
@Instantiator(STANDARD) public class MagicInstantiator<T> extends java.lang.Object implements ObjectInstantiator<T>
This instantiator will correctly bypass the constructors by instantiating the class using the default constructor from Object. It will be allowed to do so by extendingMagicAccessorImplwhich prevents its children to be verified by the class loader
-
-
Field Summary
Fields Modifier and Type Field Description private static intCONSTANT_POOL_COUNTprivate static byte[]CONSTRUCTOR_CODEprivate static intCONSTRUCTOR_CODE_ATTRIBUTE_LENGTHprivate static java.lang.StringCONSTRUCTOR_DESCprivate static java.lang.StringCONSTRUCTOR_NAMEprivate static intINDEX_CLASS_INTERFACEprivate static intINDEX_CLASS_OBJECTprivate static intINDEX_CLASS_SUPERCLASSprivate static intINDEX_CLASS_THISprivate static intINDEX_CLASS_TYPEprivate static intINDEX_METHODREF_OBJECT_CONSTRUCTORprivate static intINDEX_NAMEANDTYPE_DEFAULT_CONSTRUCTORprivate static intINDEX_UTF8_CODE_ATTRIBUTEprivate static intINDEX_UTF8_CONSTRUCTOR_DESCprivate static intINDEX_UTF8_CONSTRUCTOR_NAMEprivate static intINDEX_UTF8_INSTANTIATOR_CLASSprivate static intINDEX_UTF8_INTERFACEprivate static intINDEX_UTF8_NEWINSTANCE_DESCprivate static intINDEX_UTF8_NEWINSTANCE_NAMEprivate static intINDEX_UTF8_OBJECTprivate static intINDEX_UTF8_SUPERCLASSprivate static intINDEX_UTF8_TYPEprivate ObjectInstantiator<T>instantiatorprivate static java.lang.StringMAGIC_ACCESSORprivate static byte[]NEWINSTANCE_CODEprivate static intNEWINSTANCE_CODE_ATTRIBUTE_LENGTH
-
Constructor Summary
Constructors Constructor Description MagicInstantiator(java.lang.Class<T> type)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ObjectInstantiator<T>getInstantiator()Get the underlying instantiator.private static java.lang.StringgetMagicClass()TnewInstance()Returns a new instance of an object.private ObjectInstantiator<T>newInstantiatorOf(java.lang.Class<T> type)private byte[]writeExtendingClass(java.lang.Class<?> type, java.lang.String className)Will generate the bytes for a class extending the type passed in parameter.
-
-
-
Field Detail
-
MAGIC_ACCESSOR
private static final java.lang.String MAGIC_ACCESSOR
-
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_INSTANTIATOR_CLASS
private static final int INDEX_UTF8_INSTANTIATOR_CLASS
- See Also:
- Constant Field Values
-
INDEX_UTF8_SUPERCLASS
private static final int INDEX_UTF8_SUPERCLASS
- See Also:
- Constant Field Values
-
INDEX_CLASS_INTERFACE
private static final int INDEX_CLASS_INTERFACE
- See Also:
- Constant Field Values
-
INDEX_UTF8_INTERFACE
private static final int INDEX_UTF8_INTERFACE
- See Also:
- Constant Field Values
-
INDEX_UTF8_NEWINSTANCE_NAME
private static final int INDEX_UTF8_NEWINSTANCE_NAME
- See Also:
- Constant Field Values
-
INDEX_UTF8_NEWINSTANCE_DESC
private static final int INDEX_UTF8_NEWINSTANCE_DESC
- See Also:
- Constant Field Values
-
INDEX_METHODREF_OBJECT_CONSTRUCTOR
private static final int INDEX_METHODREF_OBJECT_CONSTRUCTOR
- See Also:
- Constant Field Values
-
INDEX_CLASS_OBJECT
private static final int INDEX_CLASS_OBJECT
- See Also:
- Constant Field Values
-
INDEX_UTF8_OBJECT
private static final int INDEX_UTF8_OBJECT
- See Also:
- Constant Field Values
-
INDEX_NAMEANDTYPE_DEFAULT_CONSTRUCTOR
private static final int INDEX_NAMEANDTYPE_DEFAULT_CONSTRUCTOR
- See Also:
- Constant Field Values
-
INDEX_CLASS_TYPE
private static final int INDEX_CLASS_TYPE
- See Also:
- Constant Field Values
-
INDEX_UTF8_TYPE
private static final int INDEX_UTF8_TYPE
- See Also:
- Constant Field Values
-
CONSTANT_POOL_COUNT
private static final int CONSTANT_POOL_COUNT
- See Also:
- Constant Field Values
-
CONSTRUCTOR_CODE
private static final byte[] CONSTRUCTOR_CODE
-
CONSTRUCTOR_CODE_ATTRIBUTE_LENGTH
private static final int CONSTRUCTOR_CODE_ATTRIBUTE_LENGTH
-
NEWINSTANCE_CODE
private static final byte[] NEWINSTANCE_CODE
-
NEWINSTANCE_CODE_ATTRIBUTE_LENGTH
private static final int NEWINSTANCE_CODE_ATTRIBUTE_LENGTH
-
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
-
instantiator
private final ObjectInstantiator<T> instantiator
-
-
Constructor Detail
-
MagicInstantiator
public MagicInstantiator(java.lang.Class<T> type)
-
-
Method Detail
-
getInstantiator
public ObjectInstantiator<T> getInstantiator()
Get the underlying instantiator.MagicInstantiatoris a wrapper around another object which implementsObjectInstantiatorinterface. This method exposes that instantiator.- Returns:
- the underlying instantiator
-
newInstantiatorOf
private ObjectInstantiator<T> newInstantiatorOf(java.lang.Class<T> type)
-
writeExtendingClass
private byte[] writeExtendingClass(java.lang.Class<?> type, java.lang.String className)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 extendclassName- name of the wrapped instantiator class- Returns:
- the byte for the class
- Throws:
ObjenesisException- is something goes wrong
-
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.
-
getMagicClass
private static java.lang.String getMagicClass()
-
-