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 116209 - Generate Code... hashCode generates bad code
Summary: Generate Code... hashCode generates bad code
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Unsupported (show other bugs)
Version: 6.x
Hardware: PC Linux
: P3 blocker (vote)
Assignee: issues@java
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-09-20 18:35 UTC by tazntig
Modified: 2007-09-26 09:14 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description tazntig 2007-09-20 18:35:21 UTC
Using:

Product Version: NetBeans IDE 6.0 M10 (build 200706281431)
Java: 1.5.0_12; Java HotSpot(TM) Client VM 1.5.0_12-b04
System: Linux version 2.6.9-55.0.6.ELsmp running on i386; UTF-8; en_US (nb) 

Observed Behavior:

Summary:
Using the "Generate Code..." feature to create equals and hashCode, the generated hashCode will not compile.

What the code generates:

To generate a hashCode for the following fields: 

    private String name;
    private Date date;

results in the following:

    public int hashCode() {
        int hash = 5;
        hash = 59 * hash + this.name != null ? this.name.hashCode() : 0;
        hash = 59 * hash + this.date != null ? this.date.hashCode() : 0;
        return hash;
    }

which causes the following compile-time error:

Compiling 1 source file to /home/lorin/NetBeans Projects/IBS Portal Packages/build/classes
Test.java:42: operator + cannot be applied to int,java.util.Date
        hash = 59 * hash + this.date != null ? this.date.hashCode() : 0;
1 error

The code should read:

    public int hashCode() {
        int hash = 5;
        hash = 59 * hash + (this.name != null ? this.name.hashCode() : 0);
        hash = 59 * hash + (this.date != null ? this.date.hashCode() : 0);
        return hash;
    }

which properly compiles.
Comment 1 Jan Lahoda 2007-09-21 09:09:42 UTC
This has been fixed some time ago, thanks for the report.
Comment 2 Jan Lahoda 2007-09-21 09:13:40 UTC
.