jfreechart
jfreechart copied to clipboard
XYLineAndShapeRenderer implements equals() but not hashcode()
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.
I've actually fixed quite a few of these but haven't committed them yet. @jfree should I go ahead and do that?
@tracylynne99 yes, thanks!
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.
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?