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

Guard against NoClassDefFoundError when trying to load Unsafe. #7432

Closed
wants to merge 1 commit into from

Conversation

normanmaurer
Copy link
Member

Motivation:

OSGI and other enviroments may not allow to even load Unsafe which will lead to an NoClassDefFoundError when trying to access it. We should guard against this.

Modifications:

Catch NoClassDefFoundError when trying to load Unsafe.

Result:

Be able to use netty with a strict OSGI config.

Motivation:

OSGI and other enviroments may not allow to even load Unsafe which will lead to an NoClassDefFoundError when trying to access it. We should guard against this.

Modifications:

Catch NoClassDefFoundError when trying to load Unsafe.

Result:

Be able to use netty with a strict OSGI config.
@@ -96,6 +96,10 @@ public Object run() {
return e;
} catch (IllegalAccessException e) {
return e;
} catch (NoClassDefFoundError e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think LinkageError might be a little more robust here, would love to hear what @jasontedor has to say.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah maybe that would be a good idea!

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the ping @johnou. I think the most specific error possible should be caught. If this throws a NoClassDefFoundError in an OSGI situation, that I think that's what should be caught here only.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, before merging, I would recommend thinking about my comment on the original issue. It's hard to support something that you do not have experience with, tests for, etc. so maybe the best path is not to make a code change here at all (because a future refactoring might "break" it again). Instead, there's an out here for users in OSGI already: either add the dependency needed, or set a flag to skip trying to use unsafe.

Copy link
Contributor

Choose a reason for hiding this comment

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

There is actually a Netty OSGI test suite 💯

Copy link
Member Author

Choose a reason for hiding this comment

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

yep ... I will try to add a test.. not idea if I will be successful tho =P

Copy link
Contributor

Choose a reason for hiding this comment

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

@normanmaurer not as easy as trying to load the class with the PaxExam runner is it? 🧀

Copy link
Contributor

Choose a reason for hiding this comment

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

Apparently it does not do much of anything as it's not catching an issue for OSGI environments that do not add the necessary dependency for unsafe that has been there for over a year (#5640). And I question having that with two of the main maintainers saying that they do not have OSGI knowledge to maintain support for it. And none of this negates my point that there's an out for OSGI already without a change needed in Netty.

Copy link
Contributor

Choose a reason for hiding this comment

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

@jasontedor I would still argue that this specific exception is not 100% related to OSGI and that Netty should be able to detect if unsafe is available or not and if it is not, fallback.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, I agree with you.

@normanmaurer
Copy link
Member Author

Unfortunately I was not able to write a test with paxexam (maybe because I don't know enough about it). That said I have read multiple sources in the internet that state that the NoClassDefFoundError is what is thrown by OSGi containers in this case. So let me merge this one and hopefully we can find someone in the future who will add a unit test .

@normanmaurer
Copy link
Member Author

Cherry-picked into 4.1 (65cacc9) and 4.0 (7ceea22)

@normanmaurer normanmaurer deleted the guard_against_no_class_def_found branch November 24, 2017 19:09
normanmaurer pushed a commit that referenced this pull request Nov 27, 2017
Motiviation:

The OSGi Test suite runs without access to sun.misc.Unsafe, and so is a good place to put a test to avoid regressing #6548.

Modification:

Added a test-case that failed before #7432.

Result:

Test for fix included.
normanmaurer pushed a commit that referenced this pull request Nov 27, 2017
Motiviation:

The OSGi Test suite runs without access to sun.misc.Unsafe, and so is a good place to put a test to avoid regressing #6548.

Modification:

Added a test-case that failed before #7432.

Result:

Test for fix included.
kiril-me pushed a commit to kiril-me/netty that referenced this pull request Feb 28, 2018
Motiviation:

The OSGi Test suite runs without access to sun.misc.Unsafe, and so is a good place to put a test to avoid regressing netty#6548.

Modification:

Added a test-case that failed before netty#7432.

Result:

Test for fix included.
pulllock pushed a commit to pulllock/netty that referenced this pull request Oct 19, 2023
Motiviation:

The OSGi Test suite runs without access to sun.misc.Unsafe, and so is a good place to put a test to avoid regressing netty#6548.

Modification:

Added a test-case that failed before netty#7432.

Result:

Test for fix included.
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.

None yet

3 participants