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

Mockito does not work with OTEL extension api in classpath #3342

Open
pradeep-tux opened this issue May 11, 2024 · 1 comment
Open

Mockito does not work with OTEL extension api in classpath #3342

pradeep-tux opened this issue May 11, 2024 · 1 comment

Comments

@pradeep-tux
Copy link

pradeep-tux commented May 11, 2024

When trying to mock classes when there is opentelemetry-javaagent-extension-api jar in the classpath, it fails with error:

Underlying exception : org.mockito.exceptions.base.MockitoException: Could not modify all classes [interface java.sql.Connection, interface java.lang.AutoCloseable, interface java.sql.Wrapper]
...
Caused by: java.lang.AbstractMethodError: Receiver class org.mockito.internal.creation.bytebuddy.InlineBytecodeGenerator$ParameterWritingVisitorWrapper does not define or inherit an implementation of the resolved method 'abstract org.objectweb.asm.ClassVisitor wrap(net.bytebuddy.description.type.TypeDescription, org.objectweb.asm.ClassVisitor, net.bytebuddy.implementation.Implementation$Context, net.bytebuddy.pool.TypePool, net.bytebuddy.description.field.FieldList, net.bytebuddy.description.method.MethodList, int, int)' of interface net.bytebuddy.asm.AsmVisitorWrapper.

It seems as if the ClassVisitor class in the asm dependency of byte-buddy (org.objectweb.asm.ClassVisitor) is being incorrectly used instead of ClassVisitor from byte-buddy's own jar (net.bytebuddy.jar.asm.ClassVisitor).

Example - https://github.com/pradeep-tux/oss-issues/tree/mockito_bytebuddy_class_override
Just run the tests within the project - those would fail with the above error

Environment:

OS: mac sonoma 14.4.1
Java: openjdk version "17.0.8.1"
Mockito: 5.11.0

@pradeep-tux pradeep-tux changed the title Mockito does not work with OTEL instrumentation jars Mockito does not work with OTEL extension in classpath May 12, 2024
@pradeep-tux pradeep-tux changed the title Mockito does not work with OTEL extension in classpath Mockito does not work with OTEL extension api in classpath May 12, 2024
@robberphex
Copy link

Current source code is using net.bytebuddy.jar.asm.ClassVisitor, which work with byte-buddy, but doesn't work with byte-buddy-dep.

But if mockito use org.objectweb.asm.ClassVisitor, will work with byte-buddy-dep, but not with byte-buddy-dep.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants