lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sh...@apache.org
Subject svn commit: r1063272 - in /lucene/dev/trunk/lucene/src: java/org/apache/lucene/search/function/OrdFieldSource.java java/org/apache/lucene/search/function/ReverseOrdFieldSource.java test/org/apache/lucene/search/function/TestOrdValues.java
Date Tue, 25 Jan 2011 13:34:48 GMT
Author: shaie
Date: Tue Jan 25 13:34:48 2011
New Revision: 1063272

URL: http://svn.apache.org/viewvc?rev=1063272&view=rev
Log:
LUCENE-1250: fix equals() to check for null and not fail on NPE (trunk)

Modified:
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/function/OrdFieldSource.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/function/ReverseOrdFieldSource.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/function/TestOrdValues.java

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/function/OrdFieldSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/function/OrdFieldSource.java?rev=1063272&r1=1063271&r2=1063272&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/function/OrdFieldSource.java
(original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/function/OrdFieldSource.java
Tue Jan 25 13:34:48 2011
@@ -99,7 +99,9 @@ public class OrdFieldSource extends Valu
   /*(non-Javadoc) @see java.lang.Object#equals(java.lang.Object) */
   @Override
   public boolean equals(Object o) {
-    if (o.getClass() !=  OrdFieldSource.class) return false;
+    if (o == this) return true;
+    if (o == null) return false;
+    if (o.getClass() != OrdFieldSource.class) return false;
     OrdFieldSource other = (OrdFieldSource)o;
     return this.field.equals(other.field);
   }

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/function/ReverseOrdFieldSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/function/ReverseOrdFieldSource.java?rev=1063272&r1=1063271&r2=1063272&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/function/ReverseOrdFieldSource.java
(original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/function/ReverseOrdFieldSource.java
Tue Jan 25 13:34:48 2011
@@ -107,7 +107,9 @@ public class ReverseOrdFieldSource exten
   /*(non-Javadoc) @see java.lang.Object#equals(java.lang.Object) */
   @Override
   public boolean equals(Object o) {
-    if (o.getClass() !=  ReverseOrdFieldSource.class) return false;
+    if (o == this) return true;
+    if (o == null) return false;
+    if (o.getClass() != ReverseOrdFieldSource.class) return false;
     ReverseOrdFieldSource other = (ReverseOrdFieldSource)o;
     return this.field.equals(other.field); 
   }

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/function/TestOrdValues.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/function/TestOrdValues.java?rev=1063272&r1=1063271&r2=1063272&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/function/TestOrdValues.java
(original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/function/TestOrdValues.java
Tue Jan 25 13:34:48 2011
@@ -253,5 +253,14 @@ public class TestOrdValues extends Funct
   private String testName() {
     return getClass().getName() + "." + getName();
   }
+  
+  // LUCENE-1250
+  public void testEqualsNull() throws Exception {
+    OrdFieldSource ofs = new OrdFieldSource("f");
+    assertFalse(ofs.equals(null));
+    
+    ReverseOrdFieldSource rofs = new ReverseOrdFieldSource("f");
+    assertFalse(rofs.equals(null));
+  }
 
 }



Mime
View raw message