From 7703ce22bdb5bfd975dc8f77d0f01c0590091e20 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Thu, 24 May 2012 12:08:06 +0000 Subject: [PATCH] LUCENE-4055: add some extra safety to FI/SI attributes git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene4055@1342215 13f79535-47bb-0310-9956-ffa450edef68 --- .../codecs/lucene3x/Lucene3xFieldInfosReader.java | 3 ++- .../codecs/lucene3x/Lucene3xSegmentInfoReader.java | 3 ++- .../codecs/lucene40/Lucene40FieldInfosReader.java | 3 ++- .../codecs/lucene40/Lucene40SegmentInfoReader.java | 3 ++- .../codecs/simpletext/SimpleTextFieldInfosReader.java | 3 ++- .../simpletext/SimpleTextSegmentInfoReader.java | 3 ++- .../src/java/org/apache/lucene/index/IndexWriter.java | 11 +++++++++-- 7 files changed, 21 insertions(+), 8 deletions(-) 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.java index 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.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.java index 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.java index 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 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.java index 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 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.java index 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.java index 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.java index 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 attributes; + if (info.info.attributes() == null) { + attributes = new HashMap(); + } else { + attributes = new HashMap(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 segFiles = new HashSet();