Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

throw IllegalArgumentException if both field name and value are empty (to avoid a confusing "term out of order" exception later)

Daniel Naber55237c881fce
diff --git a/CHANGES.txt b/CHANGES.txt
index 238618130fa..894ea8ad9f3 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -13,6 +13,10 @@ API Changes
2. DisjunctionSumScorer is no longer public.
(Paul Elschot via Otis Gospodnetic)
+
+ 3. Creating a Field with both an empty name and an empty value
+ now throws an IllegalArgumentException
+ (Daniel Naber)
Bug fixes
diff --git a/src/java/org/apache/lucene/document/Field.java b/src/java/org/apache/lucene/document/Field.java
index 627f56e23ac..dc2c7eb1897 100644
--- a/src/java/org/apache/lucene/document/Field.java
+++ b/src/java/org/apache/lucene/document/Field.java
@@ -238,6 +238,8 @@ public final class Field implements Serializable {
throw new NullPointerException("name cannot be null");
if (value == null)
throw new NullPointerException("value cannot be null");
+ if (name.length() == 0 && value.length() == 0)
+ throw new IllegalArgumentException("name and value cannot both be empty");
if (index == Index.NO && store == Store.NO)
throw new IllegalArgumentException("it doesn't make sense to have a field that "
+ "is neither indexed nor stored");