Apache Lucene open-source search software
LUCENE-4055: add some extra safety to FI/SI attributes
Robert Muir7703ce22bdb5
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xFieldInfosReader.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xFieldInfosReader.javaindex 86f3735bcd8..3774fedf8e7 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xFieldInfosReader.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xFieldInfosReader.java@@ -16,6 +16,7 @@ package org.apache.lucene.codecs.lucene3x;* limitations under the License.*/import java.io.IOException;+import java.util.Collections;import java.util.Set;import org.apache.lucene.codecs.FieldInfosReader;@@ -100,7 +101,7 @@ class Lucene3xFieldInfosReader extends FieldInfosReader {storePayloads = false;}infos[i] = new FieldInfo(name, isIndexed, fieldNumber, storeTermVector,- omitNorms, storePayloads, indexOptions, null, isIndexed && !omitNorms? Type.FIXED_INTS_8 : null, null);+ omitNorms, storePayloads, indexOptions, null, isIndexed && !omitNorms? Type.FIXED_INTS_8 : null, Collections.<String,String>emptyMap());}if (input.getFilePointer() != input.length()) {diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xSegmentInfoReader.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xSegmentInfoReader.javaindex c7287d28589..20ed71041a5 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xSegmentInfoReader.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xSegmentInfoReader.java@@ -18,6 +18,7 @@ package org.apache.lucene.codecs.lucene3x;*/import java.io.IOException;+import java.util.Collections;import java.util.HashMap;import java.util.HashSet;import java.util.Map;@@ -266,7 +267,7 @@ public class Lucene3xSegmentInfoReader extends SegmentInfoReader {// nocommit: convert normgen into attributes?SegmentInfo info = new SegmentInfo(dir, version, segmentName, docCount, normGen, isCompoundFile,- null, diagnostics, attributes);+ null, diagnostics, Collections.unmodifiableMap(attributes));info.setFiles(files);SegmentInfoPerCommit infoPerCommit = new SegmentInfoPerCommit(info, delCount, delGen);diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosReader.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosReader.javaindex f79ce9ed72c..b396cd0a2b0 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosReader.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosReader.java@@ -1,6 +1,7 @@package org.apache.lucene.codecs.lucene40;import java.io.IOException;+import java.util.Collections;import java.util.Map;import java.util.Set;@@ -94,7 +95,7 @@ public class Lucene40FieldInfosReader extends FieldInfosReader {final DocValues.Type normsType = getDocValuesType((byte) ((val >>> 4) & 0x0F));final Map<String,String> attributes = input.readStringStringMap();infos[i] = new FieldInfo(name, isIndexed, fieldNumber, storeTermVector,- omitNorms, storePayloads, indexOptions, docValuesType, normsType, attributes);+ omitNorms, storePayloads, indexOptions, docValuesType, normsType, Collections.unmodifiableMap(attributes));}if (input.getFilePointer() != input.length()) {diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfoReader.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfoReader.javaindex 24f0416340f..90f5347ac1f 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfoReader.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfoReader.java@@ -18,6 +18,7 @@ package org.apache.lucene.codecs.lucene40;*/import java.io.IOException;+import java.util.Collections;import java.util.Map;import java.util.Set;@@ -52,7 +53,7 @@ public class Lucene40SegmentInfoReader extends SegmentInfoReader {final Set<String> files = input.readStringSet();final SegmentInfo si = new SegmentInfo(dir, version, segment, docCount, normGen, isCompoundFile,- null, diagnostics, attributes);+ null, diagnostics, Collections.unmodifiableMap(attributes));si.setFiles(files);success = true;diff --git a/lucene/core/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldInfosReader.java b/lucene/core/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldInfosReader.javaindex f93649d4d7e..6ea9ca2390a 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldInfosReader.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldInfosReader.java@@ -18,6 +18,7 @@ package org.apache.lucene.codecs.simpletext;*/import java.io.IOException;+import java.util.Collections;import java.util.HashMap;import java.util.Map;@@ -114,7 +115,7 @@ public class SimpleTextFieldInfosReader extends FieldInfosReader {}infos[i] = new FieldInfo(name, isIndexed, fieldNumber, storeTermVector,- omitNorms, storePayloads, indexOptions, docValuesType, normsType, atts);+ omitNorms, storePayloads, indexOptions, docValuesType, normsType, Collections.unmodifiableMap(atts));}if (input.getFilePointer() != input.length()) {diff --git a/lucene/core/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSegmentInfoReader.java b/lucene/core/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSegmentInfoReader.javaindex 95a7439dc97..deeaf389b77 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSegmentInfoReader.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSegmentInfoReader.java@@ -18,6 +18,7 @@ package org.apache.lucene.codecs.simpletext;*/import java.io.IOException;+import java.util.Collections;import java.util.HashMap;import java.util.HashSet;import java.util.Map;@@ -107,7 +108,7 @@ public class SimpleTextSegmentInfoReader extends SegmentInfoReader {}SegmentInfo info = new SegmentInfo(directory, version, segmentName, docCount,- null, isCompoundFile, null, diagnostics, attributes);+ null, isCompoundFile, null, diagnostics, Collections.unmodifiableMap(attributes));info.setFiles(files);success = true;return info;diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.javaindex 1c309b3ad6f..0ed13292aeb 100644--- a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java+++ b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java@@ -2375,6 +2375,13 @@ public class IndexWriter implements Closeable, TwoPhaseCommit {"",Lucene3xSegmentInfoFormat.SI_EXTENSION);+ // copy the attributes map, we modify it for the preflex case+ final Map<String,String> attributes;+ if (info.info.attributes() == null) {+ attributes = new HashMap<String,String>();+ } else {+ attributes = new HashMap<String,String>(info.info.attributes());+ }if (hasSharedDocStore) {// only violate the codec this way if it's preflex &// shares doc stores@@ -2389,7 +2396,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit {codecDocStoreFiles.add(IndexFileNames.segmentFileName(dsName, "", "tvd"));}// change docStoreSegment to newDsName- info.info.putAttribute(Lucene3xSegmentInfoFormat.DS_NAME_KEY, newDsName);+ attributes.put(Lucene3xSegmentInfoFormat.DS_NAME_KEY, newDsName);}//System.out.println("copy seg=" + info.info.name + " version=" + info.info.getVersion());@@ -2397,7 +2404,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit {// Same SI as before but we change directory, name and docStoreSegment:SegmentInfo newInfo = new SegmentInfo(directory, info.info.getVersion(), segName, info.info.getDocCount(),info.info.getNormGen(), info.info.getUseCompoundFile(),- info.info.getCodec(), info.info.getDiagnostics(), info.info.attributes());+ info.info.getCodec(), info.info.getDiagnostics(), Collections.unmodifiableMap(attributes));SegmentInfoPerCommit newInfoPerCommit = new SegmentInfoPerCommit(newInfo, info.getDelCount(), info.getDelGen());Set<String> segFiles = new HashSet<String>();