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

NullPointerException when load tinylog with BootstrapClassLoader #39

Closed
cspinetta opened this issue Feb 1, 2017 · 3 comments · Fixed by kamon-io/kanela#32
Closed

NullPointerException when load tinylog with BootstrapClassLoader #39

cspinetta opened this issue Feb 1, 2017 · 3 comments · Fixed by kamon-io/kanela#32
Labels

Comments

@cspinetta
Copy link

First of all, thank you very much for this useful log library! We are using it in kamon-agent.

For some integration tests we need to load tinylog with the BootstrapClassLoader, and this is when this problem manifests itself.

The problem happens when it tries to do things like this:

Configurator.class.getClassLoader().getResourceAsStream(file);

The calling Configurator.class.getClassLoader() returns null since this is the way to say that it was loaded by the bootstrap class loader.

The fix is very simple. For example introducing a method like this:

private static InputStream getResourceFromFile(String file) {
    final ClassLoader classLoader = Configurator.class.getClassLoader();
    if (classLoader == null) {
      return ClassLoader.getSystemResourceAsStream(file);
    } else {
      return classLoader.getResourceAsStream(file);
    }
  }

And call it from any place where the resource is required.

Let me know if you are agreed with this change and I'll be happy to send a PR.

@pmwmedia pmwmedia added the bug label Feb 2, 2017
@cspinetta
Copy link
Author

@pmwmedia yes, of course. This weekend I'll be working on this.

@github-actions
Copy link

github-actions bot commented Oct 9, 2022

This closed issue has been locked automatically. However, please feel free to file a new issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging a pull request may close this issue.

2 participants