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

JNR doesn't respect context classloader #8

Open
btiernay opened this issue Oct 13, 2015 · 3 comments
Open

JNR doesn't respect context classloader #8

btiernay opened this issue Oct 13, 2015 · 3 comments

Comments

@btiernay
Copy link
Contributor

See jnr/jnr-ffi#51 for the issue.

This could be fixed in the library using something like:

  /**
   * Workaround for unfortunate system class loader usage.
   * 
   * @see https://github.com/jnr/jnr-ffi/issues/51
   */
  @SneakyThrows
  private void patchFfi() {
    ClosureManager closureManager = NativeRuntime.getInstance().getClosureManager();

    // Get inner class loader
    val classLoader = findField(closureManager.getClass(), "classLoader");
    classLoader.setAccessible(true);
    val asmClassLoader = classLoader.get(closureManager);

    // Update to use context class loader over the default system class loader
    val parent = findField(asmClassLoader.getClass(), "parent");
    parent.setAccessible(true);
    parent.set(asmClassLoader, Thread.currentThread().getContextClassLoader());
  }

Thoughts?

@pron
Copy link
Contributor

pron commented Oct 14, 2015

Can you explain what the problem is?

@btiernay
Copy link
Contributor Author

If there is a non-standard non-system classloader in play, this causes issues. In my case, I'm using a classloader that knows how to read from nested jars. It is good practice to use context classloader over system for this reason

@pron
Copy link
Contributor

pron commented Oct 14, 2015

OK, can you submit a PR with the fix?

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