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.

Bug 124163

Summary: Have "Generate hashCode()" generate positive instead of negative tests
Product: java Reporter: matthies <matthies>
Component: EditorAssignee: Dusan Balek <dbalek>
Status: NEW ---    
Severity: blocker    
Priority: P3    
Version: 6.x   
Hardware: PC   
OS: Windows XP   
Issue Type: ENHANCEMENT Exception Reporter:

Description matthies 2007-12-17 21:09:28 UTC
"Generate hashCode()" generates code like:

    this.field != null ? this.field.hashCode() : 0

It is generally preferable to express logical conditions without negation when there is the choice. (There are 
situations where there is no choice, such as an 'if' on a negative condition whith no 'else' branch. But this is not 
the case here.) I'd like to suggest to generate

    this.field == null ? 0 : this.field.hashCode()

instead. Besides getting rid of the (double) negation ("is not not an object"), it also places the simple case ("0") 
first, which minimizes the mental stack when reading such code.