Unsafe { public <T> T unsafeNewInstance(Class<T> clazz) { try { if (unsafeAllocateInstance != null) { return (T) unsafeAllocateInstance.invoke(unsafe, clazz); } else { try { return clazz.getConstructor().newInstance(); } catch (final Exception e) { throw new IllegalStateException("Failed to allocateInstance of Proxy class " + clazz.getName(), e); } } } catch (IllegalAccessException e) { throw new IllegalStateException("Failed to allocateInstance of Proxy class " + clazz.getName(), e); } catch (InvocationTargetException e) { Throwable throwable = e.getTargetException() != null ? e.getTargetException() : e; throw new IllegalStateException("Failed to allocateInstance of Proxy class " + clazz.getName(), throwable); } } Unsafe(); Class<T> defineAndLoadClass(ClassLoader classLoader, String proxyName, byte[] proxyBytes); T unsafeNewInstance(Class<T> clazz);  }
@Test public void ensureUnsafeIsAvailable() { final Unsafe unsafe = new Unsafe(); final SpyConstructor obj = unsafe.unsafeNewInstance(SpyConstructor.class); assertNotNull(obj); assertFalse(obj.called); }