lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jpou...@apache.org
Subject [2/4] lucene-solr:master: LUCENE-8460: Better argument validation in StoredField
Date Thu, 30 Aug 2018 14:45:28 GMT
LUCENE-8460: Better argument validation in StoredField

Signed-off-by: Namgyu Kim <kng0828@gmail.com>
Signed-off-by: Adrien Grand <jpountz@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/a30eeae7
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/a30eeae7
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/a30eeae7

Branch: refs/heads/master
Commit: a30eeae7956c8c59037ca1c08e7f69474da10e7a
Parents: e2fc49c
Author: Namgyu Kim <kng0828@gmail.com>
Authored: Wed Aug 29 00:46:49 2018 +0900
Committer: Adrien Grand <jpountz@gmail.com>
Committed: Thu Aug 30 16:44:56 2018 +0200

----------------------------------------------------------------------
 lucene/CHANGES.txt                              |  2 ++
 .../java/org/apache/lucene/document/Field.java  | 30 +++++++++++---------
 .../org/apache/lucene/document/StoredField.java | 23 +++++++++------
 3 files changed, 33 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/a30eeae7/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 409419f..a9f93b9 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -272,6 +272,8 @@ Improvements
 * LUCENE-8446: The UnifiedHighlighter's DefaultPassageFormatter now treats overlapping matches
in
   the passage as merged (as if one larger match).  (David Smiley)
 
+* LUCENE-8460: Better argument validation in StoredField. (Namgyu Kim)
+
 Other:
 
 * LUCENE-8366: Upgrade to ICU 62.1. Emoji handling now uses Unicode 11's

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/a30eeae7/lucene/core/src/java/org/apache/lucene/document/Field.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/document/Field.java b/lucene/core/src/java/org/apache/lucene/document/Field.java
index cbb559a..467fec7 100644
--- a/lucene/core/src/java/org/apache/lucene/document/Field.java
+++ b/lucene/core/src/java/org/apache/lucene/document/Field.java
@@ -169,9 +169,8 @@ public class Field implements IndexableField {
    * @param name field name
    * @param value byte array pointing to binary content (not copied)
    * @param type field type
-   * @throws IllegalArgumentException if the field name is null,
-   *         or the field's type is indexed()
-   * @throws NullPointerException if the type is null
+   * @throws IllegalArgumentException if the field name, value or type
+   *         is null, or the field's type is indexed().
    */
   public Field(String name, byte[] value, IndexableFieldType type) {
     this(name, value, 0, value.length, type);
@@ -187,12 +186,11 @@ public class Field implements IndexableField {
    * @param offset starting position of the byte array
    * @param length valid length of the byte array
    * @param type field type
-   * @throws IllegalArgumentException if the field name is null,
-   *         or the field's type is indexed()
-   * @throws NullPointerException if the type is null
+   * @throws IllegalArgumentException if the field name, value or type
+   *         is null, or the field's type is indexed().
    */
   public Field(String name, byte[] value, int offset, int length, IndexableFieldType type)
{
-    this(name, new BytesRef(value, offset, length), type);
+    this(name, value != null ? new BytesRef(value, offset, length) : null, type);
   }
 
   /**
@@ -203,9 +201,8 @@ public class Field implements IndexableField {
    * @param name field name
    * @param bytes BytesRef pointing to binary content (not copied)
    * @param type field type
-   * @throws IllegalArgumentException if the field name is null,
-   *         or the field's type is indexed()
-   * @throws NullPointerException if the type is null
+   * @throws IllegalArgumentException if the field name, bytes or type
+   *         is null, or the field's type is indexed().
    */
   public Field(String name, BytesRef bytes, IndexableFieldType type) {
     if (name == null) {
@@ -214,9 +211,12 @@ public class Field implements IndexableField {
     if (bytes == null) {
       throw new IllegalArgumentException("bytes must not be null");
     }
+    if (type == null) {
+      throw new IllegalArgumentException("type must not be null");
+    }
+    this.name = name;
     this.fieldsData = bytes;
     this.type = type;
-    this.name = name;
   }
 
   // TODO: allow direct construction of int, long, float, double value too..?
@@ -226,10 +226,9 @@ public class Field implements IndexableField {
    * @param name field name
    * @param value string value
    * @param type field type
-   * @throws IllegalArgumentException if either the name or value
+   * @throws IllegalArgumentException if either the name, value or type
    *         is null, or if the field's type is neither indexed() nor stored(), 
    *         or if indexed() is false but storeTermVectors() is true.
-   * @throws NullPointerException if the type is null
    */
   public Field(String name, String value, IndexableFieldType type) {
     if (name == null) {
@@ -238,13 +237,16 @@ public class Field implements IndexableField {
     if (value == null) {
       throw new IllegalArgumentException("value must not be null");
     }
+    if (type == null) {
+      throw new IllegalArgumentException("type must not be null");
+    }
     if (!type.stored() && type.indexOptions() == IndexOptions.NONE) {
       throw new IllegalArgumentException("it doesn't make sense to have a field that "
         + "is neither indexed nor stored");
     }
-    this.type = type;
     this.name = name;
     this.fieldsData = value;
+    this.type = type;
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/a30eeae7/lucene/core/src/java/org/apache/lucene/document/StoredField.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/document/StoredField.java b/lucene/core/src/java/org/apache/lucene/document/StoredField.java
index 12b529c..7dc5a99 100644
--- a/lucene/core/src/java/org/apache/lucene/document/StoredField.java
+++ b/lucene/core/src/java/org/apache/lucene/document/StoredField.java
@@ -40,12 +40,13 @@ public class StoredField extends Field {
    * FieldType}.
    * @param name field name
    * @param type custom {@link FieldType} for this field
-   * @throws IllegalArgumentException if the field name is null.
+   * @throws IllegalArgumentException if the field name or type
+   *         is null.
    */
   protected StoredField(String name, FieldType type) {
     super(name, type);
   }
-  
+
   /**
    * Expert: allows you to customize the {@link
    * FieldType}.
@@ -54,7 +55,8 @@ public class StoredField extends Field {
    * @param name field name
    * @param bytes byte array pointing to binary content (not copied)
    * @param type custom {@link FieldType} for this field
-   * @throws IllegalArgumentException if the field name is null.
+   * @throws IllegalArgumentException if the field name, value or type
+   *         is null.
    */
   public StoredField(String name, BytesRef bytes, FieldType type) {
     super(name, bytes, type);
@@ -66,7 +68,8 @@ public class StoredField extends Field {
    * not to change it until you're done with this field.
    * @param name field name
    * @param value byte array pointing to binary content (not copied)
-   * @throws IllegalArgumentException if the field name is null.
+   * @throws IllegalArgumentException if the field name or value
+   *         is null.
    */
   public StoredField(String name, byte[] value) {
     super(name, value, TYPE);
@@ -80,7 +83,8 @@ public class StoredField extends Field {
    * @param value byte array pointing to binary content (not copied)
    * @param offset starting position of the byte array
    * @param length valid length of the byte array
-   * @throws IllegalArgumentException if the field name is null.
+   * @throws IllegalArgumentException if the field name or value
+   *         is null.
    */
   public StoredField(String name, byte[] value, int offset, int length) {
     super(name, value, offset, length, TYPE);
@@ -92,7 +96,8 @@ public class StoredField extends Field {
    * not to change it until you're done with this field.
    * @param name field name
    * @param value BytesRef pointing to binary content (not copied)
-   * @throws IllegalArgumentException if the field name is null.
+   * @throws IllegalArgumentException if the field name or value
+   *         is null.
    */
   public StoredField(String name, BytesRef value) {
     super(name, value, TYPE);
@@ -102,7 +107,8 @@ public class StoredField extends Field {
    * Create a stored-only field with the given string value.
    * @param name field name
    * @param value string value
-   * @throws IllegalArgumentException if the field name or value is null.
+   * @throws IllegalArgumentException if the field name or value
+   *         is null.
    */
   public StoredField(String name, String value) {
     super(name, value, TYPE);
@@ -114,7 +120,8 @@ public class StoredField extends Field {
    * @param name field name
    * @param value string value
    * @param type custom {@link FieldType} for this field
-   * @throws IllegalArgumentException if the field name or value is null.
+   * @throws IllegalArgumentException if the field name, value or type
+   *         is null.
    */
   public StoredField(String name, String value, FieldType type) {
     super(name, value, type);


Mime
View raw message