Skip to content

Commit

Permalink
Make .equals(null) not throw NPE (#84)
Browse files Browse the repository at this point in the history
* build.xml: use source and target 1.8

The codebase uses method references, which requires source 1.8. Target
must be at least as high as source.

* Allow .equals(null) to work

Three classes have .equals methods which throw exceptions for
.equals(null). Fix them.
  • Loading branch information
matvore authored Apr 10, 2023
1 parent 60653bc commit 943bd62
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
<mkdir dir="${build}/classes/" />
<javac srcdir="${source}"
destdir="${build}/classes/"
target="1.5"
source="1.5"
target="1.8"
source="1.8"
debug="on" debuglevel="lines,vars,source"
includeantruntime="false"
fork="true" />
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/dd/plist/NSData.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public String getBase64EncodedData() {

@Override
public boolean equals(Object obj) {
if (obj == null) return false;
return obj.getClass().equals(this.getClass()) && Arrays.equals(((NSData) obj).bytes, this.bytes);
}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/dd/plist/NSDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public Date getDate() {

@Override
public boolean equals(Object obj) {
if (obj == null) return false;
return obj.getClass().equals(this.getClass()) && this.date.equals(((NSDate) obj).getDate());
}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/dd/plist/NSDictionary.java
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ public int count() {

@Override
public boolean equals(Object obj) {
if (obj == null) return false;
return obj.getClass().equals(this.getClass()) && ((NSDictionary) obj).dict.equals(this.dict);
}

Expand Down

0 comments on commit 943bd62

Please sign in to comment.