Skip to content

Commit ce996dc

Browse files
authored
[ci maven-central-release] Merge pull request #2046 from mockito/include-synthetic
Do not exclude synthetic constructors from instrumentation. Fixes #2040.
2 parents b6ae6cf + 4a40f58 commit ce996dc

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/main/java/org/mockito/internal/creation/bytebuddy/InlineBytecodeGenerator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ public InlineBytecodeGenerator(
9191
new ByteBuddy()
9292
.with(TypeValidation.DISABLED)
9393
.with(Implementation.Context.Disabled.Factory.INSTANCE)
94-
.with(MethodGraph.Compiler.ForDeclaredMethods.INSTANCE);
94+
.with(MethodGraph.Compiler.ForDeclaredMethods.INSTANCE)
95+
.ignore(isSynthetic().and(not(isConstructor())).or(isDefaultFinalizer()));
9596
mocked = new WeakConcurrentSet<>(WeakConcurrentSet.Cleaner.INLINE);
9697
flatMocked = new WeakConcurrentSet<>(WeakConcurrentSet.Cleaner.INLINE);
9798
String identifier = RandomString.make();

src/main/java/org/mockito/internal/creation/bytebuddy/MockMethodAdvice.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,13 +397,14 @@ public MethodVisitor wrap(
397397
.getDeclaredMethods()
398398
.filter(isConstructor().and(not(isPrivate())));
399399
int arguments = Integer.MAX_VALUE;
400-
boolean visible = false;
400+
boolean packagePrivate = true;
401401
MethodDescription.InDefinedShape current = null;
402402
for (MethodDescription.InDefinedShape constructor : constructors) {
403403
if (constructor.getParameters().size() < arguments
404-
&& (!visible || constructor.isPackagePrivate())) {
404+
&& (packagePrivate || !constructor.isPackagePrivate())) {
405+
arguments = constructor.getParameters().size();
406+
packagePrivate = constructor.isPackagePrivate();
405407
current = constructor;
406-
visible = constructor.isPackagePrivate();
407408
}
408409
}
409410
if (current != null) {

0 commit comments

Comments
 (0)