jfreechart icon indicating copy to clipboard operation
jfreechart copied to clipboard

XYLineAndShapeRenderer implements equals() but not hashcode()

Open tadrinth opened this issue 3 years ago • 4 comments

We have a class which inherits from XYLineAndShapeRenderer in order to override one of its methods. Snyk, our security scanner, is flagging that our class implements equals() but not hashcode().

We would appreciate it if this class and its parents implemented both methods.

We use Lombok which provides a helpful @EqualsAndHashCode implementation which generates these methods correctly for you based on the fields of the class. That may be the easiest way to implement both methods.

tadrinth avatar Sep 28 '21 21:09 tadrinth

I've actually fixed quite a few of these but haven't committed them yet. @jfree should I go ahead and do that?

tracylynne99 avatar Sep 29 '21 00:09 tracylynne99

@tracylynne99 yes, thanks!

jfree avatar Sep 30 '21 06:09 jfree

I committed a fix for this on the v1.5.x and master branches. But as Tracy noted, this issue affects many other classes as well.

jfree avatar Oct 04 '21 05:10 jfree

I was just reviewing the hashCode implementation, and noticed that you didn't include the 'legendLine' in there, but it is being compared in the equals function. Doesn't that violate the contract between equals and hashCode? I thought that whatever goes in equals must be included in hashCode - always. Are there exceptions to this?

tracylynne99 avatar Oct 12 '21 17:10 tracylynne99