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
Using a maven project with the following configuration, the test will throw a NullPointerException.
Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-17T20:33:14+02:00)
Java version: 9.0.4, vendor: Oracle Corporation
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
package testbench;
public abstract class Bakery {
protected Object flour;
private Object flour() {
if (flour == null) {
synchronized (this) {
if (flour == null) {
flour = createFlour();
}
}
}
return flour;
}
protected abstract Object createFlour();
@Override
public boolean equals(final Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (!(obj instanceof Bakery)) return false;
return flour().equals(((Bakery) obj).flour());
}
@Override
public int hashCode() {
return flour().hashCode();
}
}
testbench/PizzaBakery.java
package testbench;
import static java.util.Objects.requireNonNull;
import java.util.function.Supplier;
public class PizzaBakery extends Bakery {
private final Supplier<Object> flourFactory;
protected PizzaBakery(final Supplier<Object> flourFactory) {
this.flourFactory = requireNonNull(flourFactory);
}
@Override
protected Object createFlour() {
return flourFactory.get();
}
public static Bakery newBakery() {
return new PizzaBakery(Object::new);
}
}
testbench/BakeryTest.java
package testbench;
import org.junit.Test;
import nl.jqno.equalsverifier.EqualsVerifier;
import nl.jqno.equalsverifier.Warning;
public class BakeryTest {
@Test
public void testEquals() throws Exception {
EqualsVerifier.forClass(PizzaBakery.class)
.suppress(Warning.NULL_FIELDS, Warning.STRICT_INHERITANCE, Warning.NONFINAL_FIELDS).verify();
}
}
What error message or stack trace does EqualsVerifier give?
java.lang.AssertionError: NullPointerException:
For more information, go to: http://www.jqno.nl/equalsverifier/errormessages
at nl.jqno.equalsverifier.EqualsVerifier.handleError(EqualsVerifier.java:375)
at nl.jqno.equalsverifier.EqualsVerifier.verify(EqualsVerifier.java:364)
at testbench.BakeryTest.testEquals(BakeryTest.java:14)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
Caused by: java.lang.NullPointerException
at testbench.PizzaBakery.createFlour(PizzaBakery.java:18)
at testbench.Bakery.flour(Bakery.java:11)
at testbench.Bakery.equals(Bakery.java:25)
at nl.jqno.equalsverifier.internal.checkers.HierarchyChecker.checkSuperProperties(HierarchyChecker.java:96)
at nl.jqno.equalsverifier.internal.checkers.HierarchyChecker.safelyCheckSuperProperties(HierarchyChecker.java:86)
at nl.jqno.equalsverifier.internal.checkers.HierarchyChecker.checkSuperclass(HierarchyChecker.java:74)
at nl.jqno.equalsverifier.internal.checkers.HierarchyChecker.check(HierarchyChecker.java:45)
at nl.jqno.equalsverifier.EqualsVerifier.verifyWithExamples(EqualsVerifier.java:425)
at nl.jqno.equalsverifier.EqualsVerifier.performVerification(EqualsVerifier.java:387)
at nl.jqno.equalsverifier.EqualsVerifier.verify(EqualsVerifier.java:358)
... 24 more
What did you expect?
A clear error message or a passed test. I can only fix the verification if I exclude the EqualsVerifier from my test.
Which version of EqualsVerifier are you using?
2.4.8
Please provide any additional information below.
The flourFactory used in PizzaBakery.createFlour() can only be null if the object was created without calling the constructor. Interestingly enough when using the following configuration with java 8, the test passes.
What steps will reproduce the problem?
Using a maven project with the following configuration, the test will throw a NullPointerException.
Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-17T20:33:14+02:00)
Java version: 9.0.4, vendor: Oracle Corporation
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
What is the code that triggers this problem?
testbench/Bakery.java
testbench/PizzaBakery.java
testbench/BakeryTest.java
What error message or stack trace does EqualsVerifier give?
What did you expect?
A clear error message or a passed test. I can only fix the verification if I exclude the EqualsVerifier from my test.
Which version of EqualsVerifier are you using?
2.4.8
Please provide any additional information below.
The
flourFactory
used inPizzaBakery.createFlour()
can only be null if the object was created without calling the constructor. Interestingly enough when using the following configuration with java 8, the test passes.The text was updated successfully, but these errors were encountered: