LUCENE-1250: fix equals() to check for null and not fail on NPE (trunk)

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1063272 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shai Erera 2011-01-25 13:34:48 +00:00
parent a20e2cd89a
commit 913a9e4491
3 changed files with 15 additions and 2 deletions

View File

@ -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);
}

View File

@ -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);
}

View File

@ -254,4 +254,13 @@ public class TestOrdValues extends FunctionTestSetup {
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));
}
}