Skip to content

Apache Lucene open-source search software

LUCENE-2177: don't accept Store for binary fields -- it must always be YES

Michael McCandless48b275af8085
diff --git a/CHANGES.txt b/CHANGES.txt
index 1d77fdd73fa..5c315ba9bc0 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -46,6 +46,10 @@ API Changes
* LUCENE-1972: Restore SortField.getComparatorSource (it was
accidentally removed in 3.0.0) (John Wang via Uwe Schindler)
+* LUCENE-2177: Deprecate the Field ctors that take byte[] and Store.
+ Since the removal of compressed fields, Store can only be YES, so
+ it's not necessary to specify. (Erik Hatcher via Mike McCandless)
+
Bug fixes
* LUCENE-2092: BooleanQuery was ignoring disableCoord in its hashCode
diff --git a/src/java/org/apache/lucene/document/Field.java b/src/java/org/apache/lucene/document/Field.java
index 224697ca953..32ccd46e248 100644
--- a/src/java/org/apache/lucene/document/Field.java
+++ b/src/java/org/apache/lucene/document/Field.java
@@ -521,11 +521,27 @@ public final class Field extends AbstractField implements Fieldable, Serializabl
*
* @param name The name of the field
* @param value The binary value
- * @param store How <code>value</code> should be stored (compressed or not)
+ * @param store Must be Store.YES
* @throws IllegalArgumentException if store is <code>Store.NO</code>
+ * @deprecated Use {@link #Field(String, byte[]) instead}
*/
+ @Deprecated
public Field(String name, byte[] value, Store store) {
- this(name, value, 0, value.length, store);
+ this(name, value, 0, value.length);
+
+ if (store == Store.NO) {
+ throw new IllegalArgumentException("binary values can't be unstored");
+ }
+ }
+
+ /**
+ * Create a stored field with binary value. Optionally the value may be compressed.
+ *
+ * @param name The name of the field
+ * @param value The binary value
+ */
+ public Field(String name, byte[] value) {
+ this(name, value, 0, value.length);
}
/**
@@ -537,8 +553,26 @@ public final class Field extends AbstractField implements Fieldable, Serializabl
* @param length Number of bytes to use for this Field, starting at offset
* @param store How <code>value</code> should be stored (compressed or not)
* @throws IllegalArgumentException if store is <code>Store.NO</code>
+ * @deprecated Use {@link #Field(String, byte[], int, int) instead}
*/
+ @Deprecated
public Field(String name, byte[] value, int offset, int length, Store store) {
+ this(name, value, offset, length);
+
+ if (store == Store.NO) {
+ throw new IllegalArgumentException("binary values can't be unstored");
+ }
+ }
+
+ /**
+ * Create a stored field with binary value. Optionally the value may be compressed.
+ *
+ * @param name The name of the field
+ * @param value The binary value
+ * @param offset Starting offset in value where this Field's bytes are
+ * @param length Number of bytes to use for this Field, starting at offset
+ */
+ public Field(String name, byte[] value, int offset, int length) {
if (name == null)
throw new IllegalArgumentException("name cannot be null");
@@ -548,10 +582,7 @@ public final class Field extends AbstractField implements Fieldable, Serializabl
this.name = StringHelper.intern(name); // field names are interned
fieldsData = value;
- if (store == Store.NO)
- throw new IllegalArgumentException("binary values can't be unstored");
-
- isStored = store.isStored();
+ isStored = true;
isIndexed = false;
isTokenized = false;
omitTermFreqAndPositions = false;