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

Avoid UnsatisfiedLinkError when native library already loaded #3045

Closed
wants to merge 1 commit into from

Conversation

humcqc
Copy link

@humcqc humcqc commented Mar 27, 2024

In certain condition the library is already loaded by another classloader.
And this exception should not stop the app.

@humcqc humcqc requested review from zachgk, frankfliu and a team as code owners March 27, 2024 15:16
Copy link
Contributor

@frankfliu frankfliu left a comment

Choose a reason for hiding this comment

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

This fix won't work. Native library loaded in one class loader is not visible to sibling class loader.

You have to use NativeHelper approach to workaround this issue.

@humcqc
Copy link
Author

humcqc commented Mar 27, 2024

Are you sure, seems jdk.internal.loader.NativeLibraries is aware of the fact that the library is loaded in whatever classloader:

// cannot be loaded by other class loaders if (loadedLibraryNames.contains(name)) { throw new UnsatisfiedLinkError("Native Library " + name + " already loaded in another classloader"); }

In the same time, I will have a look at the NativeHelper workaround

@humcqc
Copy link
Author

humcqc commented Mar 27, 2024

After some investigation in the java code, you right there is a static set that contains already loaded Libraries name but not the library itself that is store in the specific classloader. Not sure we can use the workaround but will try.

This PR can be deleted.

@humcqc humcqc closed this Mar 27, 2024
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.

2 participants