Skip to content

fix(ant): log messages from analyzer worker threads - #8880

Open
tinobino wants to merge 2 commits into
dependency-check:mainfrom
tinobino:fix/ant-logging-worker-threads
Open

tinobino wants to merge 2 commits into
dependency-check:mainfrom
tinobino:fix/ant-logging-worker-threads

Conversation

@tinobino

@tinobino tinobino commented Nov 3, 2026

Copy link
Copy Markdown

Description of Change

Since the move to the SLF4J 2 service provider (dfa99e8, released in 12.2.1), AntTaskHolder keeps the current Ant task in a plain ThreadLocal. The task is only set on the Ant main thread (in the Check, Update and Purge constructors/execute), but Engine.executeAnalysisTasks runs analyzeDependency in executor threads. There AntTaskHolder.getTask() returns null, and AntLoggerAdapter silently drops the message.

As a result, everything logged from analyzers while running as an Ant task is lost. For example the UnusedSuppressionRuleAnalyzer logs Suppression Rule had zero matches: ... at INFO, but nothing shows up in the Ant output, although the analyzer itself runs (Finished Unused Suppression Rule Analyzer is logged from the main thread and is visible). Before dfa99e8, StaticLoggerBinder held the task in a process-wide singleton, so these messages were shown.

This change makes AntTaskHolder use an InheritableThreadLocal. Threads started by the task (such as the engine's analysis threads) inherit the task and log through it, while parallel Ant tasks still do not see each other's task, which was the reason for the ThreadLocal in the first place.

Note: AntTaskHolder.remove() only clears the value of the calling thread. The executors in Engine are created per analyzer and shut down afterwards, so they do not keep a stale task.

Related issues

Have test cases been added to cover the new functionality?

yes

AntSlf4jServiceProviderTest.testLogOutputOfWorkerThreadRoutedThroughAntTask logs from an executor thread and verifies that the message reaches the Ant task. It fails without this change ("zero interactions with this mock") and passes with it.

@boring-cyborg boring-cyborg Bot added ant changes to ant tests test cases labels Nov 3, 2026
tinobino and others added 2 commits November 3, 2026 10:25
Messages logged from a thread started by the task are currently dropped,
as AntTaskHolder does not make the task available to other threads. This
test fails until that is changed.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
AntTaskHolder used a plain ThreadLocal since the move to the SLF4J 2
service provider (dfa99e8). The engine runs analyzers in executor
threads, where no task was set, so AntLoggerAdapter dropped all their
messages, e.g. "Suppression Rule had zero matches" of the
UnusedSuppressionRuleAnalyzer. Use an InheritableThreadLocal so threads
started by the task log through it, while parallel Ant tasks stay apart.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ant changes to ant tests test cases

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants