gnodet commented on PR #704: URL: https://github.com/apache/creadur-rat/pull/704#issuecomment-5106067152
### Latest commit: `MatcherBuilderTracker` + `StandardCollection` thread-safety fixes Based on the earlier audit discussion, this commit (18a41490) includes two additional fixes: #### 1. `MatcherBuilderTracker`: `HashMap` → `ConcurrentHashMap` The singleton `MatcherBuilderTracker` uses a `synchronized instance()` method, but once the instance is obtained, `addBuilderImpl()` and `getMatcherBuilder()` access the underlying `HashMap` without synchronization. In a parallel Maven build, concurrent `put()`/`get()` on a `HashMap` can cause infinite loops (hash bucket cycles) or lost entries. **Fix:** One-line change — `new HashMap<>()` → `new ConcurrentHashMap<>()`. #### 2. `StandardCollection`: `Supplier<AbstractFileProcessorBuilder>` instead of shared instances This is the `GitIgnoreBuilder`/`HgIgnoreBuilder` issue discussed [earlier](https://github.com/apache/creadur-rat/pull/704#issuecomment-5105540076). The `StandardCollection` enum constants stored shared singleton builder instances: ```java GIT(..., new GitIgnoreBuilder()) MERCURIAL(..., new HgIgnoreBuilder()) BAZAAR(..., new BazaarIgnoreBuilder()) CVS(..., new CVSIgnoreBuilder()) ``` These builders contain mutable state: - `AbstractFileProcessorBuilder.levelBuilders` — a `TreeMap` populated during `build()`, then `clear()`'d - `HgIgnoreBuilder.state` — a `Syntax` enum toggled during parsing Since enum constants are singletons, concurrent threads calling `build()` on the same shared instance would corrupt each other's state. **Fix:** Store a `Supplier<AbstractFileProcessorBuilder>` instead, so each `fileProcessorBuilder()` call creates a fresh builder: ```java GIT(..., GitIgnoreBuilder::new) // was: new GitIgnoreBuilder() MERCURIAL(..., HgIgnoreBuilder::new) // was: new HgIgnoreBuilder() ``` Both fixes pass the full build locally (`mvn clean install -B` — BUILD SUCCESS). -- 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]
