-
Notifications
You must be signed in to change notification settings - Fork 75
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
java.lang.AssertionError: Significant fields: hashCode relies on serialVersionUID, but equals does not. These objects are equal, but probably shouldn't be: #159
Comments
Thanks for reporting this. I'm on vacation now, I will take a look when I get back. |
I can't be sure until I see your implementation of the My first guess is that the EqualsVerifier probably gets it mixed up with If that's not it, I need more information about your class. Ideally a complete class that reproduces the issue, that I can simply copy and paste into my IDE. Analysing these kinds of issues really takes up a lot of my free time. |
I'll see what I can do to provide a more complete repro later, though equalsverifer changes but yeah, I'll see about providing more repro... |
not so easy to reproduce in an isolated context... and I'd have to refix our super impls to fix all the symmetry and reflexivity errors to repro... some day... |
EqualsVerifier does indeed treat static final fields specially, because you're right, you can't change them. But it does iterate over all of them. Perhaps something happens in your code between the moment it inspects the field and the moment it decides to skip it because it's static and final. Do you want me to keep this issue open while you try to isolate the problem? |
oh, I don't know, I probably won't put any more effort into reproducing until such time that we reimplement equals, and I'm not sure when that'll be. |
OK, I'll close the issue then. If you decide to reproduce it after all, you're free to re-open it or file a new ticket. |
This can be reproduced by cloning my repo https://github.com/eborgbjerg/chessshell-api-1.git |
@eborgbjerg Thanks! I took a look at your class. The underlying cause is that I agree that the current message is quite misleading though. I'll see if I can do something about it. |
Ok, I also tried adding That gives the error Then, I tried adding Then I get It looks like the static fields on the Square class enter the picture, not sure whether this is correct though? Apart from the above, I think I should change hashCode () to use a precalculated (final) value. But maybe the static fields would still get in the way of the unit test. Another option (and maybe the best) would be to rewrite the Square class as an enum. |
The underlying problem is that the fields used to determine You can fix that by syncing those up (e.g. by removing your |
I was able to get the unit test working (with the original version of Square) by using these options: Thank you very much for your help, and for the tips for other improvements! |
…s don't obscure issues in non-static fields
I've just released version 3.4.3. In your situation, you will now get the |
I can add more details later if necessary, I can't find a direct call to hashing serialVersionUID, I'm guessing this happens because of Serializable, by java itself.
tried adding it to equals inside of the
instanceof
but that doesn't helpThe text was updated successfully, but these errors were encountered: