Tools or VM agents to verify hashCode/equals/compareTo contracts

Alan Bateman Alan.Bateman at oracle.com
Thu Apr 4 01:35:24 PDT 2013


On 03/04/2013 21:44, Kelly O'Hair wrote:
> Does anyone know of any Tools or VM agents to verify 
> hashCode/equals/compareTo contracts?
> E.g. That equals() agrees with compareTo(), and hashCode() on the 
> equals() objects is the same?
>
> The jdk7 TimSort change seems to be shaking out places where these 
> contracts are not followed, just curious if there are any VM a gets or 
> tools that might help find these at runtime.
>
> -kto
I'm not aware of any tools for this. It might be possible to create an 
agent that works brute force and invokes equals to check equality of 
random objects in the heap, if they are equal then it could check that 
their hashCode is equal and if they are Comparable check that the 
compareTo returns 0.

On The TimSort then I assume you know there is a system property to use 
merge sort (this will of course hide the problem as before but useful as 
a get-of-jail card if you need it).

-Alan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/serviceability-dev/attachments/20130404/4db9ae06/attachment-0001.html 


More information about the serviceability-dev mailing list