benwtrent commented on code in PR #13331:
URL: https://github.com/apache/lucene/pull/13331#discussion_r1584982931


##########
lucene/core/src/java/org/apache/lucene/index/FieldInfo.java:
##########
@@ -628,12 +630,17 @@ public String getAttribute(String key) {
    * If the value of the attributes for a same field is changed between the 
documents, the behaviour
    * after merge is undefined.
    */
-  public String putAttribute(String key, String value) {
-    return attributes.put(key, value);
+  public synchronized String putAttribute(String key, String value) {
+    HashMap<String, String> newMap = new HashMap<>(attributes);
+    String oldValue = newMap.put(key, value);
+    // This needs to be thread-safe as multiple threads may be updating 
(different) attributes
+    // concurrently due to concurrent merging.
+    attributes = Collections.unmodifiableMap(newMap);

Review Comment:
   I don't understand why we are copying the map, why not use a 
`ConcurrentHashMap`?
   
   Is this because we don't want this changing at all after something calls 
`attributes()`?



-- 
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: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to