You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I noticed that Logger.traceEntry in the Scala wrapper currently lacks the safety checks present in the Java Core API, leading to potential crashes.
There are two issues here:
NPE Risk: It calls .toString on params.head immediately without checking if the parameter is null.
Eager Evaluation: It evaluates the arguments before checking if the TRACE level is enabled. This means if an object has a heavy or faulty toString, it triggers an exception even if logging is explicitly disabled (e.g., set to FATAL).
Reproduction:
vallogger=Logger(classOf[MyClass])
// 1. Causes NullPointerException
logger.traceEntry(null, null)
// 2. Causes crash (or performance hit) even if Level is FATAL/OFF// because toString is called before the level check.
logger.traceEntry(newObject {
overridedeftoString=thrownewRuntimeException("Boom")
}, "dummy")
Proposed Fix:
The method should check delegate.isTraceEnabled first to ensure lazy evaluation, and handle null parameters gracefully to match the fail-safe behavior of Log4j Core.
Hi,
I noticed that
Logger.traceEntryin the Scala wrapper currently lacks the safety checks present in the Java Core API, leading to potential crashes.There are two issues here:
.toStringonparams.headimmediately without checking if the parameter is null.toString, it triggers an exception even if logging is explicitly disabled (e.g., set to FATAL).Reproduction:
Proposed Fix:
The method should check
delegate.isTraceEnabledfirst to ensure lazy evaluation, and handle null parameters gracefully to match the fail-safe behavior of Log4j Core.I am working on a PR to fix this.