Problem with Generate equals() and hashcode() under 7.0.4

Updated to 7.0.4 last week and I've just noticed a potential problem with Generate.. equals() and hashcode(). Whenever I mark some fields not to be included the equals() method appears as asked, but the hashcode() uses all the objects fields regardless in it's hash calculation.

Don't see a plugin, or at least it's no obvious so I guess it's the built-in generate. Is this a known problem? is it a plugin conflict? can anybody else reproduce it? try..


and generate a equals & hashcode using only jeff..

Hoping this is new to 7.0.4 I've generated many, many hundreds of classes this way in the past and haven't always checked the methods generated.

4 comments
Comment actions Permalink

Should I take it from the silence it's only my copy of IntelliJ that's generating broken (unbalanced) equals() and hashcode() methods?

In the above example if I hit ]]>, Generate.., equals() and hashcode() and deselect everything but jeff I get:


Which definatly is busted, easy enough to see in this example, but not so with more complex objects esp. as generated equals and hascode aren't particlarly pretty to look at.

0
Comment actions Permalink

I did not check recently, but IIRC there are 2 pages in the wizard , one for equals and one for hashcode, where you can select different fields.

0
Comment actions Permalink

Ah-ha yes that was it.

Well that's a badly designed wizard, it makes it easier to create unbalanced equals and hashcodes as finished as always available and the defaults are everything. Surely you'd expect the two choices to be synchronized by default and have an extra option to customize each selection in the unlikely event you'd ever need to do that via the wizard.

Make it easier to do the right thing, not the very wrong thing. Has this changed recently? Sure I've only made the choice once in the past (or forced to do it twice) although saying that I have been using IDEA since 2.0..

0
Comment actions Permalink

The equals/hashcode dialog changed in IntelliJ 7.x. I am not a big fan of it as it allows you to do what you pointed out.

If I remember correctly prior to IntelliJ 7 it wasn't possible to create a non-matching equals/hashcode. IntelliJ 7 introduced the possibility of shooting yourself in the foot.

Glad I am not the only one that thinks this.

Maybe a JIRA issue should be opened on this?

0

Please sign in to leave a comment.