Class MagicInstantiator<T>

java.lang.Object
org.objenesis.instantiator.exotic.MagicInstantiator<T>
All Implemented Interfaces:
ObjectInstantiator<T>

@Instantiator(STANDARD) public class MagicInstantiator<T> extends 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 extending MagicAccessorImpl which prevents its children to be verified by the class loader
  • Field Details

    • MAGIC_ACCESSOR

      private static final String MAGIC_ACCESSOR
    • 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_INSTANTIATOR_CLASS

      private static final int INDEX_UTF8_INSTANTIATOR_CLASS
      See Also:
    • INDEX_UTF8_SUPERCLASS

      private static final int INDEX_UTF8_SUPERCLASS
      See Also:
    • INDEX_CLASS_INTERFACE

      private static final int INDEX_CLASS_INTERFACE
      See Also:
    • INDEX_UTF8_INTERFACE

      private static final int INDEX_UTF8_INTERFACE
      See Also:
    • INDEX_UTF8_NEWINSTANCE_NAME

      private static final int INDEX_UTF8_NEWINSTANCE_NAME
      See Also:
    • INDEX_UTF8_NEWINSTANCE_DESC

      private static final int INDEX_UTF8_NEWINSTANCE_DESC
      See Also:
    • INDEX_METHODREF_OBJECT_CONSTRUCTOR

      private static final int INDEX_METHODREF_OBJECT_CONSTRUCTOR
      See Also:
    • INDEX_CLASS_OBJECT

      private static final int INDEX_CLASS_OBJECT
      See Also:
    • INDEX_UTF8_OBJECT

      private static final int INDEX_UTF8_OBJECT
      See Also:
    • INDEX_NAMEANDTYPE_DEFAULT_CONSTRUCTOR

      private static final int INDEX_NAMEANDTYPE_DEFAULT_CONSTRUCTOR
      See Also:
    • INDEX_CLASS_TYPE

      private static final int INDEX_CLASS_TYPE
      See Also:
    • INDEX_UTF8_TYPE

      private static final int INDEX_UTF8_TYPE
      See Also:
    • CONSTANT_POOL_COUNT

      private static final int CONSTANT_POOL_COUNT
      See Also:
    • 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 String CONSTRUCTOR_NAME
      See Also:
    • CONSTRUCTOR_DESC

      private static final String CONSTRUCTOR_DESC
      See Also:
    • instantiator

      private final ObjectInstantiator<T> instantiator
  • Constructor Details

    • MagicInstantiator

      public MagicInstantiator(Class<T> type)
  • Method Details

    • getInstantiator

      public ObjectInstantiator<T> getInstantiator()
      Get the underlying instantiator. MagicInstantiator is a wrapper around another object which implements ObjectInstantiator interface. This method exposes that instantiator.
      Returns:
      the underlying instantiator
    • newInstantiatorOf

      private ObjectInstantiator<T> newInstantiatorOf(Class<T> type)
    • writeExtendingClass

      private byte[] writeExtendingClass(Class<?> type, 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 extend
      className - 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 interface ObjectInstantiator<T>
      Returns:
      A new instance of an object.
    • getMagicClass

      private static String getMagicClass()