gnodet opened a new pull request, #704:
URL: https://github.com/apache/creadur-rat/pull/704

   ## Summary
   
   - Replace plain `static` fields in `DefaultLog` and `DeprecationReporter` 
with `ThreadLocal` storage so each thread (e.g. parallel Maven reactor threads 
with `mvn -T`) gets its own logger and deprecation reporter instance
   - Add `removeInstance()` / `removeLogReporter()` cleanup methods to prevent 
`ThreadLocal` memory leaks in long-lived thread pools
   - Preserve backward-compatible public API — all existing callers continue to 
work unchanged
   
   ## Problem
   
   Both `DefaultLog.instance` and `DeprecationReporter.consumer` were plain 
`static` fields (no `volatile`, no synchronization). Every mojo constructor 
(`AbstractRatMojo()`) overwrites the JVM-wide `DefaultLog.instance` singleton 
via `DefaultLog.setInstance(makeLog())`, where `makeLog()` creates a `Log` that 
delegates to `this.getLog()` — the Maven logger for *that specific module*.
   
   In a parallel Maven build (`mvn -T`):
   1. Module A's mojo constructor sets `DefaultLog.instance` → A's logger
   2. Module B's mojo constructor sets `DefaultLog.instance` → B's logger
   3. Module A starts executing — its log messages silently route to **B's 
logger**
   4. Log output is interleaved, misrouted, or lost entirely
   
   Both mojos declare `@Mojo(threadSafe = true)`, telling Maven they are safe 
for parallel execution, but the global singleton mutations make this incorrect.
   
   The same race condition affects `DeprecationReporter.consumer`, which is 
also a plain static field overwritten in each generated `BaseRatMojo` 
constructor.
   
   ## Fix
   
   Replace both global singletons with `ThreadLocal` storage:
   - `DefaultLog`: `private static Log instance` → `private static final 
ThreadLocal<Log> INSTANCE`
   - `DeprecationReporter`: `private static Consumer<Option> consumer` → 
`private static final ThreadLocal<Consumer<Option>> CONSUMER`
   
   Each thread now gets its own isolated logger and deprecation reporter, 
making `@Mojo(threadSafe = true)` correct.
   
   ## Test plan
   
   - [x] Full Maven build passes (`mvn clean install -B` — all modules)
   - [x] No new SpotBugs violations introduced
   - [ ] Manual verification: run RAT check on a multi-module project with `mvn 
-T 4 apache-rat:check` to confirm log messages route to the correct module
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)


-- 
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]

Reply via email to