Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constructor dispatch #2021

Merged
merged 2 commits into from Aug 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means that the build will now fail when an Illegal Access is performed? Nice!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will log it in more detail but fail would be the much more sensible option. Weird I did not think of it, that's of course a much better value...

}