gnodet commented on code in PR #704:
URL: https://github.com/apache/creadur-rat/pull/704#discussion_r3672131020


##########
apache-rat-core/src/main/java/org/apache/rat/analysis/matchers/SPDXMatcherFactory.java:
##########
@@ -40,18 +40,29 @@
  * SPDX identifiers are specified by the Software Package Data Exchange(R) also
  * known as SPDX(R) project from the Linux foundation.
  * </p>
+ * <p>
+ * Each factory instance maintains its own matcher map and per-document match
+ * state ({@code lastMatch}, {@code checked}). In multi-threaded environments
+ * (e.g. parallel Maven builds), use {@link #newInstance()} or a
+ * {@code ThreadLocal<SPDXMatcherFactory>} to obtain a per-thread factory
+ * instead of the shared {@link #INSTANCE}.
+ * </p>
  *
  * @see <a href="https://spdx.dev/ids/";>List of Ids at spdx.dev</a>
  */
 public final class SPDXMatcherFactory {
 
     /**
-     * The collection of all matchers produced by this factory.
+     * The collection of all matchers produced by this factory instance.
      */
-    private static final Map<String, SPDXMatcherFactory.Match> MATCHER_MAP = 
new HashMap<>();
+    private final Map<String, SPDXMatcherFactory.Match> matcherMap = new 
HashMap<>();
 
     /**
-     * The instance of this factory.
+     * The shared instance of this factory.
+     * <p>
+     * <b>Not thread-safe</b> — in multi-threaded environments use
+     * {@link #newInstance()} to create per-thread instances instead.
+     * </p>
      */
     public static final SPDXMatcherFactory INSTANCE = new SPDXMatcherFactory();

Review Comment:
   Done — deprecated `INSTANCE` with `@Deprecated` and a Javadoc note that it 
will be removed in 1.0.0.



##########
apache-rat-core/src/main/java/org/apache/rat/analysis/matchers/SPDXMatcherFactory.java:
##########
@@ -77,12 +88,25 @@ public final class SPDXMatcherFactory {
     private boolean checked;
 
     /**
-     * Constructor.
+     * Constructor. Creates a new factory with its own matcher map and match 
state.
      */
-    private SPDXMatcherFactory() {
+    SPDXMatcherFactory() {

Review Comment:
   Good catch — made it `private`. The `newInstance()` factory method is in the 
same class, so it can still call it.



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