Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

Logger.traceEntry throws NPE on null arguments and eagerly evaluates toString #101

Description

@SpaceLeam

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:

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.


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions