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

Transient field is not ignored #196

Closed
mark-grunn opened this issue Jun 20, 2018 · 5 comments
Closed

Transient field is not ignored #196

mark-grunn opened this issue Jun 20, 2018 · 5 comments
Labels

Comments

@mark-grunn
Copy link

mark-grunn commented Jun 20, 2018

What steps will reproduce the problem?

Attempting to verify a class with a transient field using lombok's @EqualsAndHashCode does not seem to run the transient fields with "withIgnoredFields"

What is the code that triggers this problem?

Model.java

@Entity
@EqualsAndHashCode
public final class Model {

    @Transient
    @EqualsAndHashCode.Exclude
    private Boolean condition;

    private String test;
}

EqualsVerifierTest.java

    @Test
    public void equalsVerifierTest() {
        EqualsVerifier<?> verifier = EqualsVerifier.forClass(pojoClass.getClazz());

        // Below code required to not fail
//        if (pojoClass.getClazz().equals(Model.class)) {
//            verifier.withIgnoredFields("condition"); // Reason: transient field
//        }
        verifier.verify();
    }

What error message or stack trace does EqualsVerifier give?

java.lang.AssertionError: Significant fields: equals does not use condition, or it is stateless.
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:361)
	at com.example.equalsverifier.EqualsverifierApplicationTests.equalsVerifierTest(EqualsVerifierTest.java:32)

What did you expect?

As noted in http://jqno.nl/equalsverifier/manual/jpa-entities/ under "Transient Fields" I would expect the transient field "condition" to be called with "withIgnoredFields".

Which version of EqualsVerifier are you using?

2.4.6

@jqno
Copy link
Owner

jqno commented Jun 20, 2018

Indeed, I was able to reproduce this issue (both with and without Lombok). I'll fix this in the next version, which I hope to release in the next few days.

@jqno jqno added the accepted label Jun 20, 2018
@srenkens
Copy link

That would be nice Jan, our team will be happy 😉
Thanks for the excellent tool

jqno added a commit that referenced this issue Jun 20, 2018
@jqno
Copy link
Owner

jqno commented Jun 20, 2018

I just released a fix!

@jqno jqno closed this as completed Jun 20, 2018
akhalikov pushed a commit to akhalikov/equalsverifier that referenced this issue Nov 6, 2019
@hohwille
Copy link

For the record: I faced this bug in latest version (3.10.1) so it is IMHO not (properly) fixed.
Maybe in my case the problem might be related to the fact that the transient filed is located in a super-class that other beans inherit that are tested via equals-verifier. The only solution I could find so far is to completely disable the static check (suppress(Warning.TRANSIENT_FIELDS)).

@jqno
Copy link
Owner

jqno commented Oct 14, 2022

Hi!
Could you please post the code that triggers this behaviour for you? I do have some tests that test the case when the @Transient annotation is present in a superclass, but maybe I'm missing something. Unfortunately, I can't figure out what exactly, from your description.

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

4 participants