SpaceLeam opened a new issue, #101:
URL: https://github.com/apache/logging-log4j-scala/issues/101
Hi,
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:
1. **NPE Risk:** It calls `.toString` on `params.head` immediately without
checking if the parameter is null.
2. **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:**
```scala
val logger = 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(new Object {
override def toString = throw new RuntimeException("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.
I am working on a PR to fix this.
---
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]