Class 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 extending MagicAccessorImpl which prevents its children to be verified by the class loader
    • Field Detail

      • MAGIC_ACCESSOR

        private static final java.lang.String MAGIC_ACCESSOR
      • 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_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_NAMEANDTYPE_DEFAULT_CONSTRUCTOR

        private static final int INDEX_NAMEANDTYPE_DEFAULT_CONSTRUCTOR
        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
    • 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 implements ObjectInstantiator interface. This method exposes that instantiator.
        Returns:
        the underlying instantiator
      • 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 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 java.lang.String getMagicClass()