Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException on uninitialized static fields #165

Closed
rewolf opened this issue Jan 12, 2017 · 4 comments
Closed

NullPointerException on uninitialized static fields #165

rewolf opened this issue Jan 12, 2017 · 4 comments
Labels

Comments

@rewolf
Copy link

rewolf commented Jan 12, 2017

What steps will reproduce the problem?

Include a static field with no value assigned

What is the code that triggers this problem?

Class under test:

public class Pojo {

    private static Integer[] MY_STATIC_THAT_MAKES_YOU_SAD;

    @Override
    public final boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || !(o instanceof Pojo)) {
            return false;
        }
        return true;
    }

    @Override
    public final int hashCode() {
        return 0;
    }
}

Test:

    @Test
    public void testEquals() throws Exception {
        EqualsVerifier.forClass(Pojo.class).suppress(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:381)
	at nl.jqno.equalsverifier.EqualsVerifier.verify(EqualsVerifier.java:370)
	at PojoTest.equals(PojoTest.java:13)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:483)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:483)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.lang.NullPointerException
	at nl.jqno.equalsverifier.FieldsChecker$ArrayFieldCheck.arrayCopy(FieldsChecker.java:261)
	at nl.jqno.equalsverifier.FieldsChecker$ArrayFieldCheck.replaceInnermostArrayValue(FieldsChecker.java:256)
	at nl.jqno.equalsverifier.FieldsChecker$ArrayFieldCheck.execute(FieldsChecker.java:245)
	at nl.jqno.equalsverifier.FieldInspector.check(FieldInspector.java:40)

What did you expect?

A proper test response. This NullPointerException is unexpected and doesn't occur with old versions of EqualsVerifier (< 2.0)

Which version of EqualsVerifier are you using?

2.+ (2.1.8)

@jqno
Copy link
Owner

jqno commented Jan 12, 2017

Reproduced, exactly as you said. Thanks for reporting this! I'll try to fix this in the next release.

@jqno jqno added the accepted label Jan 12, 2017
@jqno jqno closed this as completed in bbabc07 Jan 12, 2017
@rewolf
Copy link
Author

rewolf commented Jan 12, 2017

Thanks for the quick response!

@jqno
Copy link
Owner

jqno commented Jan 13, 2017 via email

@jqno
Copy link
Owner

jqno commented Jan 14, 2017

I've just made a release for this: version 2.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants