Donate Share

commonclipse

Tracker: Bugs

5 Weird error - ID: 1663512
Last Update: Comment added ( nobody )

I have run into a strange problem: when running this basic Java class I get
always false although is should be true. Commons-lang 2.2, commonclipse
1.3.0

Am I missing something here?

Thanks in advance

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

public class Dummy {

static String NAME = "test";

public static void main(String[] args) {
Dummy d1 = new Dummy(NAME);
Dummy d2 = new Dummy(NAME);
System.out.println(d1.equals(d2));
}

private String name;

public Dummy(String name) {
this.name = name;
}

public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}


public boolean equals(Object object) {
if (!(object instanceof Dummy)) {
return false;
}
Dummy rhs = (Dummy) object;
return new EqualsBuilder().appendSuper(super.equals(object)).append(
this.name, rhs.name).isEquals();
}

public int hashCode() {
return new HashCodeBuilder(-202685193, -95195117).appendSuper(
super.hashCode()).append(this.name).toHashCode();
}
}


rocha_84 ( rocha_84 ) - 2007-02-19 14:28

5

Open

None

fabrizio giustina

Commonclipse

commonclipse 1.1.0

Public


Comment ( 1 )




Date: 2008-04-10 19:07
Sender: nobody

Logged In: NO

This is because the EqualsBuilder.appendSuper() is appending the
super.equals() method. Your class' super is Object. Object.equals()
compares the references and returns true only if the objects are the same.
Remove the appendSuper() from the EqualsBuilder where the class doesn't
extend anything (except, of course, Object).

While not as harmful, you should likewise remove the
HashCodeBuilder.appendSuper() where the super is Object.


Log in to comment.

Attached File

No Files Currently Attached

Change

No changes have been made to this artifact.