dweiss commented on code in PR #15457:
URL: https://github.com/apache/lucene/pull/15457#discussion_r2567515741
##########
lucene/core/src/java/org/apache/lucene/index/FieldInfo.java:
##########
@@ -675,7 +674,7 @@ public synchronized String putAttribute(String key, String
value) {
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);
+ attributes = Map.copyOf(newMap);
Review Comment:
I wouldn't replace unmodifiableMap with copyOf. There is no point in doing
it, I think.
##########
lucene/core/src/java/org/apache/lucene/store/DataInput.java:
##########
@@ -248,17 +243,17 @@ public DataInput clone() {
public Map<String, String> readMapOfStrings() throws IOException {
int count = readVInt();
if (count == 0) {
- return Collections.emptyMap();
+ return Map.of();
} else if (count == 1) {
- return Collections.singletonMap(readString(), readString());
+ return Map.of(readString(), readString());
Review Comment:
These changes only work if input arguments are non-null, which I'm not sure
we ever enforced or documented so it would be an incompatible change. Applies
to both sets and maps.
```
import java.util.*;
public class Test {
public static void main(String[] args) {
String s = null;
System.out.println("This works");
Collections.singleton(s);
System.out.println("This does not");
Set.of(s);
}
}
```
To play it safe, I'd limit the change to just removing the treeset (and
leaving hash set). Then this can be backported with no problems. If you'd like
to move to non-null arguments then this needs to be documented in the
migration, method javadocs, etc.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]