Class ProxyingInstantiator<T>

java.lang.Object
org.objenesis.instantiator.basic.ProxyingInstantiator<T>
All Implemented Interfaces:
ObjectInstantiator<T>

@Instantiator(STANDARD) public class ProxyingInstantiator<T> extends 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 a VerifyError is you do that. However, using -Xverify:none should make it work
  • Field Details

  • Constructor Details

    • ProxyingInstantiator

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

    • nameForSubclass

      private static String nameForSubclass(Class<?> parent)
    • 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.
    • writeExtendingClass

      private static byte[] writeExtendingClass(Class<?> type, 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 extend
      subclassName - name to give to the subclass
      Returns:
      the byte for the class
      Throws:
      ObjenesisException - is something goes wrong