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 extendingMagicAccessorImpl
which prevents its children to be verified by the class loader
-
-
Field Summary
Fields Modifier and Type Field Description private static int
CONSTANT_POOL_COUNT
private static byte[]
CONSTRUCTOR_CODE
private static int
CONSTRUCTOR_CODE_ATTRIBUTE_LENGTH
private static java.lang.String
CONSTRUCTOR_DESC
private static java.lang.String
CONSTRUCTOR_NAME
private static int
INDEX_CLASS_INTERFACE
private static int
INDEX_CLASS_OBJECT
private static int
INDEX_CLASS_SUPERCLASS
private static int
INDEX_CLASS_THIS
private static int
INDEX_CLASS_TYPE
private static int
INDEX_METHODREF_OBJECT_CONSTRUCTOR
private static int
INDEX_NAMEANDTYPE_DEFAULT_CONSTRUCTOR
private static int
INDEX_UTF8_CODE_ATTRIBUTE
private static int
INDEX_UTF8_CONSTRUCTOR_DESC
private static int
INDEX_UTF8_CONSTRUCTOR_NAME
private static int
INDEX_UTF8_INSTANTIATOR_CLASS
private static int
INDEX_UTF8_INTERFACE
private static int
INDEX_UTF8_NEWINSTANCE_DESC
private static int
INDEX_UTF8_NEWINSTANCE_NAME
private static int
INDEX_UTF8_OBJECT
private static int
INDEX_UTF8_SUPERCLASS
private static int
INDEX_UTF8_TYPE
private ObjectInstantiator<T>
instantiator
private static java.lang.String
MAGIC_ACCESSOR
private static byte[]
NEWINSTANCE_CODE
private static int
NEWINSTANCE_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.String
getMagicClass()
T
newInstance()
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.MagicInstantiator
is a wrapper around another object which implementsObjectInstantiator
interface. 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: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.
-
getMagicClass
private static java.lang.String getMagicClass()
-
-