This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
Product Version = NetBeans IDE 8.0.2 (Build 201411181905) Operating System = Mac OS X version 10.10.5 running on x86_64 Java; VM; Vendor = 1.8.0_45 Runtime = Java HotSpot(TM) 64-Bit Server VM 25.45-b02 I will attach a class example which reproduces the problem. Take the attached file, go at the bottom, where the IndexToReplicate class is, press CTRL-I when in the compareTo() method and choose the "equals() and hashCode()..." methods. Check the four class members and create the new methods. It will produce this hashCode method: @Override public int hashCode() { int hash = 7; return hash; } which is useless. Now delete that method and repeat the creation, press CTRL-I and choose "hashCode()..." It will now produce a better method: @Override public int hashCode() { int hash = 7; hash = 17 * hash + this.indexNumber; hash = 17 * hash + Objects.hashCode(this.projectName); hash = 17 * hash + Objects.hashCode(this.lastUpdatedOn); hash = 17 * hash + (int) (this.currentTime ^ (this.currentTime >>> 32)); return hash; }
Created attachment 156580 [details] IDE log
Created attachment 156581 [details] Java file to show the hashCode method creation bug Use this file to reproduce the bug
Reassigned for further evaluation.
Did you check the members in BOTH equals() and hashCode() choosers during the initial equals + hashCode chooser ? The chooser for hashCode() only generator will respect choices made for existing equals() - the same when generating equals() when hashCode already exists.
Sorry I don't get what you mean. If you use the file I attached, and go to the bottom of that file, you should be able to reproduce the problem. Search for the following comment: // GO HERE AND PRESS CTRL-I to produce equals() and hashCode(). Check all the 4 members.
OK, some misunderstandings may be there. 1/ I admit I didn't use CTRL-I: that shortcut stands for either Copy or QuickSearch in the standard keymap, which seems rather unrelated to this topic). But used Alt-Ins to bring up "Generate" popup menu - also reachable from Source / Insert code. Check if the CTRL-I keystroke does the same in your setup. If not, please go to Tools - Options - Keymaps, search for CTRL-I keystroke and note the attached action name in the bug report. Though unlikely, there may be different hashCode() generators. 2/ In absence of both equals and hashCode(), the generator offers to create both equals and hashCode. See the attached screenshot -- if I check items in BOTH columns, I'll get a properly generated hashcode: @Override public int hashCode() { int hash = 5; hash = 53 * hash + this.indexNumber; hash = 53 * hash + Objects.hashCode(this.projectName); hash = 53 * hash + Objects.hashCode(this.lastUpdatedOn); hash = 53 * hash + (int) (this.currentTime ^ (this.currentTime >>> 32)); return hash; } When the right column is left at its default (none checked), the generated hashCode looks as in your report.
Created attachment 158284 [details] Screenshot of the hashcode+equals tool
I have redone the steps I had described a couple of months ago, and now it doesn't show any problems while creating the hashCode method, even using CTRL-I. Of course I checked all or some of the members but I am sure I was not getting the right methods 2 months ago. Now it works well, with my example. I am still on NetBeans IDE 8.0.2 (Build 201411181905), some updates were installed, but I have not taken note of what I have updated so far. Or it can depend on some other reasons. If I hit that again I will produce a more thorough documentation. Thanks, -Antonio
OK, is the dialog on the screenshot the same as in your IDE (to be sure I am looking at the same feature) ? I used also 8.0.2 release (NetBeans IDE 8.0.2 (Build 201411181905)) for testing - the same result.
Yes, it's the same dialog.
OK, closing as works for me then.