Skip to content

Commit

Permalink
[ci maven-central-release] Merge pull request #2021 from mockito/cons…
Browse files Browse the repository at this point in the history
…tructor-dispatch

Constructor dispatch
  • Loading branch information
raphw committed Aug 24, 2020
2 parents 065dd12 + 57f7db8 commit 76a91f0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
Expand Up @@ -265,12 +265,18 @@ public InlineByteBuddyMockMaker() {
} else if (type.isInstance(spy)) {
return spy;
} else {
// Unexpected construction of non-spied object
throw new MockitoException(
"Unexpected spy for "
+ type.getName()
+ " on instance of "
+ object.getClass().getName());
isSuspended.set(true);
try {
// Unexpected construction of non-spied object
throw new MockitoException(
"Unexpected spy for "
+ type.getName()
+ " on instance of "
+ object.getClass().getName(),
object instanceof Throwable ? (Throwable) object : null);
} finally {
isSuspended.set(false);
}
}
} else if (currentConstruction.get() != type) {
return null;
Expand Down
Expand Up @@ -95,6 +95,7 @@ class InstrumentationMemberAccessor implements MemberAccessor {
INITIALIZATION_ERROR = throwable;
}

@SuppressWarnings("unused")
private final MethodHandle getModule, isOpen, redefineModule, privateLookupIn;

InstrumentationMemberAccessor() {
Expand All @@ -116,7 +117,7 @@ class InstrumentationMemberAccessor implements MemberAccessor {
.findVirtual(
module,
"isOpen",
MethodType.methodType(boolean.class, String.class, module));
MethodType.methodType(boolean.class, String.class));
redefineModule =
MethodHandles.publicLookup()
.findVirtual(
Expand Down Expand Up @@ -330,9 +331,12 @@ public void set(Field field, Object target, Object value) throws IllegalAccessEx
}

private void assureOpen(Object module, String packageName) throws Throwable {
if (!(Boolean)
DISPATCHER.invokeWithArguments(
isOpen, module, packageName, DISPATCHER.getModule())) {
// It would be more reliable to check if a module's package already is opened to
// the dispatcher module from before. Unfortunately, there is no reliable check
// for doing so since the isOpen(String, Module) method always returns true
// if the second argument is an unnamed module. Therefore, for now, we need
// to reopen packages even if they are already opened to the dispatcher module.
if (!(Boolean) DISPATCHER.invokeWithArguments(isOpen, module, packageName)) {
DISPATCHER.invokeWithArguments(
redefineModule.bindTo(INSTRUMENTATION),
module,
Expand Down
4 changes: 4 additions & 0 deletions subprojects/inline/inline.gradle
Expand Up @@ -12,3 +12,7 @@ tasks.javadoc.enabled = false
//required by the "StressTest.java" and "OneLinerStubStressTest.java"
test.maxHeapSize = "256m"
retryTest.maxHeapSize = "256m"

test {
jvmArgs '--illegal-access=debug'
}

0 comments on commit 76a91f0

Please sign in to comment.