You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What steps will reproduce the problem?
1. Create a class which allows null fields.
2. Create example instances and pass them to forRelaxedExamples().
3. add some unequal examples.
4. verify()
Here is a small test case that reproduces the problem:
@Test
public void testName() throws Exception {
class Pojo {
public Pojo(int id) {
this.id = id;
}
private int id;
private String string;
private Object object;
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + id;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!(obj instanceof Pojo))
return false;
Pojo other = (Pojo) obj;
if (id != other.id)
return false;
return true;
}
}
EqualsVerifier.forRelaxedEqualExamples(new Pojo(1), new Pojo(1), new Pojo(1))
.andUnequalExample(new Pojo(2)).verify();
}
What is the code (equals method, hashCode method, relevant fields) that
triggers the problem?
null fields in object examples.
What error message does EqualsVerifier give?
java.lang.AssertionError: java.lang.NullPointerException
What stacktrace does EqualsVerifier print, when called with the debug()
method?
testName(com.twosigma.corpacts.api.v1.DividendDTOTest)
java.lang.AssertionError: java.lang.NullPointerException:
For more information, go to:
http://code.google.com/p/equalsverifier/wiki/ErrorMessages
at nl.jqno.equalsverifier.util.Assert.fail(Assert.java:96)
at nl.jqno.equalsverifier.EqualsVerifier.handleError(EqualsVerifier.java:359)
at nl.jqno.equalsverifier.EqualsVerifier.verify(EqualsVerifier.java:342)
at com.twosigma.corpacts.api.v1.DividendDTOTest.testName(DividendDTOTest.java:53)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
What did you expect?
It appears to be trying to compare fields by calling equals() on their values.
I expected it to check for null value first.
What version of EqualsVerifier are you using?
1.1.4
Please provide any additional information below.
The NullPointerException is triggered by line 190 in ExamplesChecker.java
(method isIdentical(T reference, T other)):
...
189: field.setAccessible(true);
--> 190: if (!field.get(reference).equals(field.get(other))) {
191: return false;
...
Original issue reported on code.google.com by [email protected] on 25 Jan 2013 at 9:46
The text was updated successfully, but these errors were encountered:
There is a NullChecker that should make sure that this kind of problem doesn't
occur. However, it doesn't seem to be working with forRelaxedEqualExamples.
Sadly, I can't really offer you a workaround for this, either. I'll fix this
for the next release.
Thanks for reporting this!
Original issue reported on code.google.com by
[email protected]
on 25 Jan 2013 at 9:46The text was updated successfully, but these errors were encountered: