Details
Description
public boolean equals(Object obj) { if (obj == null) return false; JavaMethod m = (JavaMethod) obj; if (m.isConstructor() != isConstructor()) return false; if (m.getName() == null) return (getName() == null); // this line(215) is incorrect if (!m.getName().equals(getName())) return false; if (m.getReturns() == null) return (getReturns() == null); // THIS line(218) is incorrect
They should be:
if(m.getName()==null && getName()!=null) return false;
and
if(m.getReturns()==null && getReturns()!=null) return false;
Otherwise, if two methods with same name and return type but different parameters will return true, which is incorrect.
Maybe other `equals` have same issue. I think it's a good idea to provide a helper method to check, e.g.:
public static boolean eq(Object obj1, Object obj2) { return obj1==obj2 || (obj1!=null && obj1.equals(obj2); } if(!eq(m.getName(), getName()) return false; if(!eq(m.getReturns(), getReturns()) return false;
Activity
Robert Scholte
made changes -
Field | Original Value | New Value |
---|---|---|
Assignee | Robert Scholte [ rfscholte ] |
Robert Scholte
made changes -
Description |
public boolean equals(Object obj) {
if (obj == null) return false; JavaMethod m = (JavaMethod) obj; if (m.isConstructor() != isConstructor()) return false; if (m.getName() == null) return (getName() == null); // this line(215) is incorrect if (!m.getName().equals(getName())) return false; if (m.getReturns() == null) return (getReturns() == null); // THIS line(218) is incorrect They should be: if(m.getName()==null && getName()!=null) return false; and if(m.getReturns()==null && getReturns()!=null) return false; Otherwise, if two methods with same name and return type but different parameters will return true, which is incorrect. Maybe other `equals` have same issue. I think it's a good idea to provide a helper method to check, e.g.: public static boolean eq(Object obj1, Object obj2) { return obj1==obj2 || (obj1!=null && obj1.equals(obj2); } if(!eq(m.getName(), getName()) return false; if(!eq(m.getReturns(), getReturns()) return false; |
{code}
public boolean equals(Object obj) { if (obj == null) return false; JavaMethod m = (JavaMethod) obj; if (m.isConstructor() != isConstructor()) return false; if (m.getName() == null) return (getName() == null); // this line(215) is incorrect if (!m.getName().equals(getName())) return false; if (m.getReturns() == null) return (getReturns() == null); // THIS line(218) is incorrect {code} They should be: {code} if(m.getName()==null && getName()!=null) return false; {code} and {code} if(m.getReturns()==null && getReturns()!=null) return false; {code} Otherwise, if two methods with same name and return type but different parameters will return true, which is incorrect. Maybe other `equals` have same issue. I think it's a good idea to provide a helper method to check, e.g.: {code} public static boolean eq(Object obj1, Object obj2) { return obj1==obj2 || (obj1!=null && obj1.equals(obj2); } if(!eq(m.getName(), getName()) return false; if(!eq(m.getReturns(), getReturns()) return false; {code} |
Robert Scholte
made changes -
Fix Version/s | 2.0 [ 15636 ] | |
Affects Version/s | 2.0-alpha [ 17493 ] | |
Affects Version/s | 2.0 [ 15636 ] |
Robert Scholte
made changes -
Status | Open [ 1 ] | Resolved [ 5 ] |
Resolution | Fixed [ 1 ] |
Robert Scholte
made changes -
Resolution | Fixed [ 1 ] | |
Status | Resolved [ 5 ] | Reopened [ 4 ] |
Robert Scholte
made changes -
Status | Reopened [ 4 ] | Resolved [ 5 ] |
Fix Version/s | 1.12.1 [ 18944 ] | |
Resolution | Fixed [ 1 ] |
is not correct. If they both null, the 2nd line will throw NPE. So it's best to use that `eq(...)` helper method: