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

Recover from duplicate class definition errors #5185

Merged
merged 4 commits into from
Jan 25, 2022

Conversation

laurit
Copy link
Contributor

@laurit laurit commented Jan 20, 2022

Resolves #5155
If there is a duplicate class definition find the class with findLoadedClass and return it instead of throwing a LinkageError. Currently no attempt is made to detect where the duplicate definition was caused by us or not. If needed we could add a ThreadLocal to detect whether helper classes were injected while defining a class and only suppress duplicate class definition errors then.

@laurit laurit requested a review from a team as a code owner January 20, 2022 11:35
Copy link
Member

@trask trask left a comment

Choose a reason for hiding this comment

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

👍

this issue has caused headaches for injecting SPI classes (since ideally we would inject them when we see the SPI interface loaded) e.g.

// we cannot use ContextDataProvider here because one of the classes that we inject implements
// this interface, causing the interface to be loaded while it's being transformed, which
// leads to duplicate class definition error after the interface is transformed and the
// triggering class loader tries to load it.

I'm in favor of adding the ThreadLocal check if that doesn't add too much complexity.

Copy link
Member

@trask trask left a comment

Choose a reason for hiding this comment

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

thx!

Comment on lines +97 to +102
mv.visitMethodInsn(
Opcodes.INVOKESTATIC,
Type.getInternalName(DefineClassContext.class),
"enter",
"()V",
false);
Copy link
Member

Choose a reason for hiding this comment

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

can you update the pseudo code above (which is really helpful) with the new enter/exit/exitAndGet?

Copy link
Member

@trask trask left a comment

Choose a reason for hiding this comment

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

thx again, I'm looking forward to trying this out by removing a couple of SPI interface instrumentation hacks

Comment on lines +87 to +89
} catch (Throwable throwable) {
DefineClassContext.exit();
throw throwable;
Copy link
Member

Choose a reason for hiding this comment

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

👍

@trask trask merged commit f2a2786 into open-telemetry:main Jan 25, 2022
@laurit laurit deleted the duplicate-class-definition branch January 25, 2022 18:03
trask added a commit that referenced this pull request Jan 26, 2022
* Recover from duplicate class definition errors

* fix hotspot8

* Suppress dupicate class definiton errors only when helper classes were injected

* exit define class context when there is an exception, update pseudocode in comment

Co-authored-by: Lauri Tulmin <ltulmin@splunk.com>
RashmiRam pushed a commit to RashmiRam/opentelemetry-auto-instr-java that referenced this pull request May 23, 2022
* Recover from duplicate class definition errors

* fix hotspot8

* Suppress dupicate class definiton errors only when helper classes were injected

* exit define class context when there is an exception, update pseudocode in comment
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

Successfully merging this pull request may close these issues.

java.lang.LinkageError thrown at startup after updating from 1.7 to 1.9
3 participants