diff --git a/lucene/src/java/org/apache/lucene/search/function/OrdFieldSource.java b/lucene/src/java/org/apache/lucene/search/function/OrdFieldSource.java index e7817da359e..4a23a1c5d9e 100644 --- a/lucene/src/java/org/apache/lucene/search/function/OrdFieldSource.java +++ b/lucene/src/java/org/apache/lucene/search/function/OrdFieldSource.java @@ -99,7 +99,9 @@ public class OrdFieldSource extends ValueSource { /*(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); } diff --git a/lucene/src/java/org/apache/lucene/search/function/ReverseOrdFieldSource.java b/lucene/src/java/org/apache/lucene/search/function/ReverseOrdFieldSource.java index 30e339d5724..bb01ca4a4b5 100644 --- a/lucene/src/java/org/apache/lucene/search/function/ReverseOrdFieldSource.java +++ b/lucene/src/java/org/apache/lucene/search/function/ReverseOrdFieldSource.java @@ -107,7 +107,9 @@ public class ReverseOrdFieldSource extends ValueSource { /*(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); } diff --git a/lucene/src/test/org/apache/lucene/search/function/TestOrdValues.java b/lucene/src/test/org/apache/lucene/search/function/TestOrdValues.java index 706eca76f43..07b07f1c317 100644 --- a/lucene/src/test/org/apache/lucene/search/function/TestOrdValues.java +++ b/lucene/src/test/org/apache/lucene/search/function/TestOrdValues.java @@ -253,5 +253,14 @@ public class TestOrdValues extends FunctionTestSetup { 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)); + } }