Skip to content

Commit e922492

Browse files
author
Robert James Oxspring
committed
OptionImpl now avoids NullPointerExceptions
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/cli/trunk@130099 13f79535-47bb-0310-9956-ffa450edef68
1 parent 1811c0b commit e922492

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

src/java/org/apache/commons/cli2/option/OptionImpl.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,29 @@ public boolean equals(final Object thatObj) {
6969
final OptionImpl that = (OptionImpl)thatObj;
7070

7171
return getId() == that.getId()
72-
&& getPreferredName().equals(that.getPreferredName())
73-
&& (getDescription() == that.getDescription()
74-
|| getDescription().equals(that.getDescription()))
75-
&& getPrefixes().equals(that.getPrefixes())
76-
&& getTriggers().equals(that.getTriggers());
72+
&& equals(getPreferredName(),that.getPreferredName())
73+
&& equals(getDescription(),that.getDescription())
74+
&& equals(getPrefixes(),that.getPrefixes())
75+
&& equals(getTriggers(),that.getTriggers());
7776
}
7877
else {
7978
return false;
8079
}
8180
}
8281

83-
public int hashCode() {
82+
private boolean equals(Object left, Object right) {
83+
if(left==null && right==null){
84+
return true;
85+
}
86+
else if(left==null || right==null){
87+
return false;
88+
}
89+
else{
90+
return left.equals(right);
91+
}
92+
}
93+
94+
public int hashCode() {
8495
int hashCode = getId();
8596
hashCode = hashCode * 37 + getPreferredName().hashCode();
8697
if (getDescription() != null) {

0 commit comments

Comments
 (0)