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

NoSuchMethodException: Record with static field. #346

Closed
nstdio opened this issue Sep 1, 2020 · 2 comments · Fixed by #347
Closed

NoSuchMethodException: Record with static field. #346

nstdio opened this issue Sep 1, 2020 · 2 comments · Fixed by #347

Comments

@nstdio
Copy link
Contributor

nstdio commented Sep 1, 2020

What steps will reproduce the problem?

Verify the record that contains a static field.

What is the code that triggers this problem?

package nl.jqno.equalsverifier.internal.checkers;

import nl.jqno.equalsverifier.EqualsVerifier;
import org.junit.Test;

public class RecordCheckerTest {

    @Test
    public void shouldVerifyProperly() {
        EqualsVerifier.forClass(Foo.class).verify();
    }
    
    public static record Foo(String a) {
        private static final int FIELD = 0;
    }
}

What error message or stack trace does EqualsVerifier give?

java.lang.AssertionError: EqualsVerifier found a problem in class nl.jqno.equalsverifier.internal.checkers.RecordCheckerTest$Foo.
-> Record: could not find suitable constructor.

For more information, go to: http://www.jqno.nl/equalsverifier/errormessages

	at nl.jqno.equalsverifier.api.SingleTypeEqualsVerifierApi.verify(SingleTypeEqualsVerifierApi.java:269)
	at nl.jqno.equalsverifier.internal.checkers.RecordCheckerTest.shouldVerifyProperly(RecordCheckerTest.java:10)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	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.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:220)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:53)
Caused by: nl.jqno.equalsverifier.internal.exceptions.AssertionException
	at nl.jqno.equalsverifier.internal.util.Assert.fail(Assert.java:75)
	at nl.jqno.equalsverifier.internal.checkers.RecordChecker.getConstructorFor(RecordChecker.java:86)
	at nl.jqno.equalsverifier.internal.checkers.RecordChecker.check(RecordChecker.java:33)
	at nl.jqno.equalsverifier.api.SingleTypeEqualsVerifierApi.verifyWithoutExamples(SingleTypeEqualsVerifierApi.java:352)
	at nl.jqno.equalsverifier.api.SingleTypeEqualsVerifierApi.performVerification(SingleTypeEqualsVerifierApi.java:320)
	at nl.jqno.equalsverifier.api.SingleTypeEqualsVerifierApi.verify(SingleTypeEqualsVerifierApi.java:267)
	... 23 more
Caused by: java.lang.NoSuchMethodException: nl.jqno.equalsverifier.internal.checkers.RecordCheckerTest$Foo.<init>(java.lang.String,int)
	at java.base/java.lang.Class.getConstructor0(Class.java:3427)
	at java.base/java.lang.Class.getConstructor(Class.java:2165)
	at nl.jqno.equalsverifier.internal.checkers.RecordChecker.getConstructorFor(RecordChecker.java:82)
	... 27 more

What did you expect?

To pass verification.

Which version of EqualsVerifier are you using?

3.4.2

Please provide any additional information below.

$ java -version
openjdk version "14.0.2" 2020-07-14
OpenJDK Runtime Environment (build 14.0.2+12-Ubuntu-118.04)
OpenJDK 64-Bit Server VM (build 14.0.2+12-Ubuntu-118.04, mixed mode, sharing)
@jqno
Copy link
Owner

jqno commented Sep 2, 2020

Thank you for the PR, much appreciated!

@jqno
Copy link
Owner

jqno commented Sep 8, 2020

I've just released this in version 3.4.3.

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

Successfully merging a pull request may close this issue.

2 participants