gnodet commented on PR #704: URL: https://github.com/apache/creadur-rat/pull/704#issuecomment-5105371635
@ottlinger Thanks for pointing to RAT-553. I looked at `HgIgnoreBuilder` and `GitIgnoreBuilder` — here's the analysis: ### Root cause: shared mutable builder instances in `StandardCollection` enum `StandardCollection` is an enum, so each constant holds **one shared instance** of the builder: ```java GIT(..., new GitIgnoreBuilder()), // line 99 — single instance for all threads MERCURIAL(..., new HgIgnoreBuilder()), // line 173 — single instance for all threads ``` `fileProcessorBuilder()` (line 294) returns that same shared instance. When `ExclusionProcessor.extractFileProcessors()` calls `builder.build(basedir)` from two reactor threads concurrently, they corrupt each other's state: 1. **`AbstractFileProcessorBuilder.levelBuilders`** (line 71) — a `TreeMap` that is populated during `build()` and `clear()`'d at line 135. Two threads writing/clearing the same `TreeMap` concurrently → `ConcurrentModificationException` or corrupted data. 2. **`HgIgnoreBuilder.state`** (line 52) — a mutable `Syntax` field (REGEXP/GLOB) reset to `REGEXP` at the start of `process()` (line 64) and toggled by `modifyEntry()` (line 72) as it parses `syntax: glob` / `syntax: regexp` directives. Two threads processing different `.hgignore` files concurrently → wrong syntax applied to entries. `GitIgnoreBuilder` itself doesn't have extra mutable instance state beyond what's inherited from `AbstractFileProcessorBuilder`, but the shared `levelBuilders` is enough to cause corruption. ### Potential fix The `StandardCollection` enum could store a `Supplier<AbstractFileProcessorBuilder>` instead of an instance, so `fileProcessorBuilder()` returns a fresh builder each time. That way each thread gets its own instance with isolated state. Happy to include this fix in the PR if you'd like — it's a focused change in `StandardCollection` and `AbstractFileProcessorBuilder`. -- 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]
