[GitHub] [lucene-solr] uschindler commented on a change in pull request #637: LUCENE-8754: Prevent ConcurrentModificationException in SegmentInfo

2019-04-09 Thread GitBox
uschindler commented on a change in pull request #637: LUCENE-8754: Prevent 
ConcurrentModificationException in SegmentInfo
URL: https://github.com/apache/lucene-solr/pull/637#discussion_r273345219
 
 

 ##
 File path: lucene/core/src/java/org/apache/lucene/index/SegmentInfo.java
 ##
 @@ -111,12 +112,12 @@ public SegmentInfo(Directory dir, Version version, 
Version minVersion, String na
 this.maxDoc = maxDoc;
 this.isCompoundFile = isCompoundFile;
 this.codec = codec;
-this.diagnostics = Objects.requireNonNull(diagnostics);
+this.diagnostics = Collections.unmodifiableMap(new 
HashMap<>(Objects.requireNonNull(diagnostics)));
 this.id = id;
 if (id.length != StringHelper.ID_LENGTH) {
   throw new IllegalArgumentException("invalid id: " + Arrays.toString(id));
 }
-this.attributes = Objects.requireNonNull(attributes);
+this.attributes = Collections.unmodifiableMap(new 
HashMap<>(Objects.requireNonNull(attributes)));
 
 Review comment:
   One thing: once master is on Java 11, this should use: 
https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Map.html#copyOf(java.util.Map)
   
   We may simplify more code doing that as Java 11 has now unmodifiable maps 
using a static initializer like Guava once had with ImmutableMap. Same for 
lists and sets.
   
   On top, if the input is unmodifiable already it does not copy, so it is more 
heap efficient.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [lucene-solr] uschindler commented on a change in pull request #637: LUCENE-8754: Prevent ConcurrentModificationException in SegmentInfo

2019-04-09 Thread GitBox
uschindler commented on a change in pull request #637: LUCENE-8754: Prevent 
ConcurrentModificationException in SegmentInfo
URL: https://github.com/apache/lucene-solr/pull/637#discussion_r273345219
 
 

 ##
 File path: lucene/core/src/java/org/apache/lucene/index/SegmentInfo.java
 ##
 @@ -111,12 +112,12 @@ public SegmentInfo(Directory dir, Version version, 
Version minVersion, String na
 this.maxDoc = maxDoc;
 this.isCompoundFile = isCompoundFile;
 this.codec = codec;
-this.diagnostics = Objects.requireNonNull(diagnostics);
+this.diagnostics = Collections.unmodifiableMap(new 
HashMap<>(Objects.requireNonNull(diagnostics)));
 this.id = id;
 if (id.length != StringHelper.ID_LENGTH) {
   throw new IllegalArgumentException("invalid id: " + Arrays.toString(id));
 }
-this.attributes = Objects.requireNonNull(attributes);
+this.attributes = Collections.unmodifiableMap(new 
HashMap<>(Objects.requireNonNull(attributes)));
 
 Review comment:
   One thing: once master is on Java 11, this should use: 
https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Map.html#copyOf(java.util.Map)
   
   We may simplify more code doing that as Java 11 has now unmodifiable maps 
using a static initializer like Guava once had with ImmutableMap. Same for 
lists and sets.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

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