-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
log4j-jul adapter makes code throws NPEs #3119
Comments
The solution for now is to set
|
The `MethodHandleFactory` and especially its `FUNC` static field are heavily used during the static initialization process. To prevent nullability problems in the static `MethodHandleFactory` fields, `StandardMethodHandleFunctionality` relies on `DebugLogger.DISABLED_LOGGER.isEnabled()` being `false` during the initialization process. If this assumption fails (as described in apache/logging-log4j2#3119) the static initialization fails. We improve the above failsafe by: - Replacing the `StandardMethodHandleFunctionality.log` field with a static `MethodHandleFactory.log` field. - The new `log` field is placed last, so it holds the value `null` until the end of static initialization. - All the usages of the `log` fields are checked to ensure that they contain a null-check.
Some libraries rely on `j.u.l.Logger.getLevel` returning the value that was set using `j.u.l.Logger.setLevel`. This PR changes #2353 so that: - By default, the **effective** configuration of the logging backend is not modified by `log4j-jul`. - Calling `setLevel` modifies the return value of `getLevel`. Both these methods should **not** be used in user code, because the **effective** level of a logger should be checked with `j.u.l.isLoggable` instead. Therefore, I don't see any potential problems with these modifications. Closes #3119
Nice catch! Thank you for debugging it this far! From my perspective the issue is caused by an initialization problem of the
In openjdk/nashorn#19 I proposed a more fool-proof way to check if the In the meantime we can add a workaround to Log4j (see #3125) that will guarantee that the (ineffective) PS: I think that both the above mentioned PRs are just workarounds for a bigger problem: Nashorn tries to modify the logging configuration of your application. I have started a thread on |
Description
I just spend 2.5 days debugging this. The error which I got is very unobvious to me as a non-Java developer. I only found the solution by trial and error and binary search.
I'm using Tomcat that I have configured to use log4j and a log of adapters to centralize the logging. The app I'm trying to run in Tomcat is the Shibboleth IDP which I have configured to use Nashorn for scripting.
When using the log4j-jul adapter with affected version I get an NPE because Nashorn is trying to set the TRACE level.
This connects back to #2353
Getting an NPE because someone is trying to use a disabled API is very hard to troubleshoot.
Configuration
Version: >=2.24.0
Operating system: "Linux"
JDK: OpenJDK Runtime Environment (build 17.0.13+11-Debian-1deb11u1)
Logs
Reproduction
I suspect setting the log level like Nashorn does it is all that's needed but I'm a deployer not a developer 🤷♂️
https://github.com/openjdk/nashorn/blob/2eb88e4024023ee8e9baacb7736f914e3aa68aa4/src/org.openjdk.nashorn/share/classes/org/openjdk/nashorn/internal/lookup/MethodHandleFactory.java#L287
The text was updated successfully, but these errors were encountered: