public class InlineBytecodeGenerator extends java.lang.Object implements BytecodeGenerator, java.lang.instrument.ClassFileTransformer
Modifier and Type | Class and Description |
---|---|
private static class |
InlineBytecodeGenerator.ParameterWritingVisitorWrapper |
Modifier and Type | Field and Description |
---|---|
private net.bytebuddy.ByteBuddy |
byteBuddy |
(package private) static java.util.Set<java.lang.Class<?>> |
EXCLUDES |
private java.lang.instrument.Instrumentation |
instrumentation |
private java.lang.Throwable |
lastException |
private WeakConcurrentSet<java.lang.Class<?>> |
mocked |
private net.bytebuddy.asm.AsmVisitorWrapper |
mockTransformer |
private static java.lang.String |
PRELOAD |
private BytecodeGenerator |
subclassEngine |
Constructor and Description |
---|
InlineBytecodeGenerator(java.lang.instrument.Instrumentation instrumentation,
WeakConcurrentMap<java.lang.Object,MockMethodInterceptor> mocks) |
Modifier and Type | Method and Description |
---|---|
private void |
addInterfaces(java.util.Set<java.lang.Class<?>> types,
java.lang.Class<?>[] interfaces) |
private <T> void |
checkSupportedCombination(boolean subclassingRequired,
MockFeatures<T> features) |
<T> java.lang.Class<? extends T> |
mockClass(MockFeatures<T> features) |
private static void |
preload()
Mockito allows to mock about any type, including such types that we are relying on ourselves.
|
byte[] |
transform(java.lang.ClassLoader loader,
java.lang.String className,
java.lang.Class<?> classBeingRedefined,
java.security.ProtectionDomain protectionDomain,
byte[] classfileBuffer) |
private <T> void |
triggerRetransformation(MockFeatures<T> features) |
private static final java.lang.String PRELOAD
static final java.util.Set<java.lang.Class<?>> EXCLUDES
private final java.lang.instrument.Instrumentation instrumentation
private final net.bytebuddy.ByteBuddy byteBuddy
private final WeakConcurrentSet<java.lang.Class<?>> mocked
private final BytecodeGenerator subclassEngine
private final net.bytebuddy.asm.AsmVisitorWrapper mockTransformer
private volatile java.lang.Throwable lastException
public InlineBytecodeGenerator(java.lang.instrument.Instrumentation instrumentation, WeakConcurrentMap<java.lang.Object,MockMethodInterceptor> mocks)
private static void preload()
mocked
set. But to look
up this instance, we need to create key instances that rely on weak reference properties. Loading the later classes will happen before
the key instances are completed what will cause Mockito to check if those key instances are themselves mocks what causes a loop which
results in a circularity error. This is not normally a problem as we explicitly check if the instance that we investigate is one of
our instance of which we hold a reference by reference equality what does not cause any code execution. But it seems like the load
order plays a role here with unloaded types being loaded before we even get to check the mock instance property. To avoid this, we are
making sure that crucuial JVM types are loaded before we create the first inline mock. Unfortunately, these types dependant on a JVM's
implementation and we can only maintain types that we know of from well-known JVM implementations such as HotSpot and extend this list
once we learn of further problematic types for future Java versions. To allow users to whitelist their own types, we do not also offer
a property that allows running problematic tests before a new Mockito version can be released and that allows us to ask users to
easily validate that whitelisting actually solves a problem as circularities could also be caused by other problems.public <T> java.lang.Class<? extends T> mockClass(MockFeatures<T> features)
mockClass
in interface BytecodeGenerator
private <T> void triggerRetransformation(MockFeatures<T> features)
private <T> void checkSupportedCombination(boolean subclassingRequired, MockFeatures<T> features)
private void addInterfaces(java.util.Set<java.lang.Class<?>> types, java.lang.Class<?>[] interfaces)
public byte[] transform(java.lang.ClassLoader loader, java.lang.String className, java.lang.Class<?> classBeingRedefined, java.security.ProtectionDomain protectionDomain, byte[] classfileBuffer)
transform
in interface java.lang.instrument.ClassFileTransformer