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

False-positive when method List.size() is used in toString() #54

Closed
GoogleCodeExporter opened this issue Mar 29, 2015 · 4 comments
Closed

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?

The field below appears in toString(), but not in equals() or in hashCode().

private final List<WebExParticipant> participants = new 
ArrayList<WebExParticipant>();


The test:

  @Test
  public void verifyEqualsAndHashCodeCorrectness() {
    WebExConference parentConference1 = new WebExConference("parentConference1", null, null, null, null);
    WebExConference parentConference2 = new WebExConference("parentConference2", null, null, null, null);

    EqualsVerifier.forClass(WebExConference.class)
                  .withPrefabValues(WebExConference.class, parentConference1, parentConference2)
                  .verify();
  }

The false error:

java.lang.AssertionError: java.lang.AbstractMethodError: 
$java.util.List$$EnhancerByCGLIB$$afc6c2c4.size()I

See the attached classes.

Original issue reported on code.google.com by [email protected] on 23 Jan 2012 at 2:53

Attachments:

@GoogleCodeExporter
Copy link
Author

Replacing participants.size() with participants in toString() does not produce 
an error.

Original comment by [email protected] on 23 Jan 2012 at 2:53

  • Added labels: ****
  • Removed labels: ****

@GoogleCodeExporter
Copy link
Author

Hi,

Thanks for your detailed issue report.

This is a known bug (see Issue 51), which I will fix in the next version. In 
the mean time, you can work around this issue by adding prefab values for 
java.util.List, like this:

    List<WebExConference> one = new ArrayList<WebExConference>();
    one.add(new WebExConference("parentConference1", null, null, null, null));
    List<WebExConference> two = new ArrayList<WebExConference>();
    two.add(new WebExConference("parentConference2", null, null, null, null));

    EqualsVerifier.forClass(WebExConference.class)
        .withPrefabValues(List.class, one, two)
        .verify();

It's not pretty, I agree, but it'll solve your problem.


Incidentally--can I ask why you added prefab values for WebExConference itself? 
If you want EqualsVerifier to test your class with specific object instances, 
it's better to use EqualsVerifier.forExamples(...). Or did this approach solve 
a specific problem for you?

Original comment by [email protected] on 23 Jan 2012 at 6:58

  • Changed state: Duplicate
  • Added labels: ****
  • Removed labels: ****

@GoogleCodeExporter
Copy link
Author

OK, thanks for this Info! I added prefab values for WebExConference because it 
is a recursive data structure, and this way I could use EqualsVerifier. The 
conference has a list of sub-conferences, which have a back-pointer to the main 
conference. Same with the participants.

Original comment by [email protected] on 24 Jan 2012 at 5:54

  • Added labels: ****
  • Removed labels: ****

@GoogleCodeExporter
Copy link
Author

Ah, yes, I see it now. I guess I missed that when I was reproducing your 
problem. Indeed, in this scenario it's necessary.
Thanks for your quick reply!

Original comment by [email protected] on 24 Jan 2012 at 7:00

  • Added labels: ****
  • Removed labels: ****

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

No branches or pull requests

1 participant