lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r637053 - in /lucene/java/trunk: CHANGES.txt src/java/org/apache/lucene/document/Document.java
Date Fri, 14 Mar 2008 11:08:32 GMT
Author: mikemccand
Date: Fri Mar 14 04:08:28 2008
New Revision: 637053

URL: http://svn.apache.org/viewvc?rev=637053&view=rev
Log:
LUCENE-1233: return empty array instead of null for certain get*s methods in Document

Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/src/java/org/apache/lucene/document/Document.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?rev=637053&r1=637052&r2=637053&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Fri Mar 14 04:08:28 2008
@@ -54,6 +54,10 @@
     deletes from the index.  This should be a somewhat lower cost
     operation than optimize.  (John Wang via Mike McCandless)
 
+ 6. LUCENE-1233: Return empty array instead of null when no fields
+    match the specified name in these methods in Document:
+    getFieldables, getFields, getValues, getBinaryValues.  (Stefan
+    Trcek vai Mike McCandless)
 
 Bug fixes
     

Modified: lucene/java/trunk/src/java/org/apache/lucene/document/Document.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/document/Document.java?rev=637053&r1=637052&r2=637053&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/document/Document.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/document/Document.java Fri Mar 14 04:08:28
2008
@@ -17,10 +17,6 @@
  * limitations under the License.
  */
 
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.search.Hits;
-import org.apache.lucene.search.Searcher;
-
 import java.util.*;             // for javadoc
 
 /** Documents are the unit of indexing and search.
@@ -196,9 +192,10 @@
     return fields;
   }
 
+  private final static Field[] NO_FIELDS = new Field[0];
+  
   /**
    * Returns an array of {@link Field}s with the given name.
-   * This method can return <code>null</code>.
    * Do not use with lazy loaded fields.
    *
    * @param name the name of the field
@@ -214,15 +211,16 @@
      }
 
      if (result.size() == 0)
-       return null;
+       return NO_FIELDS;
 
      return (Field[])result.toArray(new Field[result.size()]);
    }
 
 
-  /**
+   private final static Fieldable[] NO_FIELDABLES = new Fieldable[0];
+
+   /**
    * Returns an array of {@link Fieldable}s with the given name.
-   * This method can return <code>null</code>.
    *
    * @param name the name of the field
    * @return a <code>Fieldable[]</code> array or <code>null</code>
@@ -237,15 +235,16 @@
      }
 
      if (result.size() == 0)
-       return null;
+       return NO_FIELDABLES;
 
      return (Fieldable[])result.toArray(new Fieldable[result.size()]);
    }
 
 
+   private final static String[] NO_STRINGS = new String[0];
+
   /**
    * Returns an array of values of the field specified as the method parameter.
-   * This method can return <code>null</code>.
    *
    * @param name the name of the field
    * @return a <code>String[]</code> of field values or <code>null</code>
@@ -259,15 +258,16 @@
     }
     
     if (result.size() == 0)
-      return null;
+      return NO_STRINGS;
     
     return (String[])result.toArray(new String[result.size()]);
   }
 
+  private final static byte[][] NO_BYTES = new byte[0][];
+
   /**
   * Returns an array of byte arrays for of the fields that have the name specified
-  * as the method parameter. This method will return <code>null</code> if no
-  * binary fields with the specified name are available.
+  * as the method parameter.
   *
   * @param name the name of the field
   * @return a  <code>byte[][]</code> of binary field values or <code>null</code>
@@ -281,7 +281,7 @@
     }
   
     if (result.size() == 0)
-      return null;
+      return NO_BYTES;
   
     return (byte[][])result.toArray(new byte[result.size()][]);
   }



Mime
View raw message