Skip to content

Commit

Permalink
Add a null check in the equals method
Browse files Browse the repository at this point in the history
Signed-off-by: Clement Escoffier <[email protected]>
  • Loading branch information
cescoffier committed Apr 26, 2015
1 parent 16422be commit 619072d
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public synchronized void stop() {
* A structure holding a webjar found in a jar file.
* Don't forget that a single jar file can contain any number of libraries.
*/
private static class DetectedWebJar {
private static final class DetectedWebJar {

/**
* The id computed as follows: {@code name-version}.
Expand Down Expand Up @@ -291,7 +291,10 @@ private DetectedWebJar(String name, String version, String path, File file) {
*/
@Override
public boolean equals(Object obj) {
return obj.getClass().equals(DetectedWebJar.class) && id.equals(((DetectedWebJar) obj).id);
// We don't use instanceOf because we don't need inheritance (the class if final).
return obj != null // Check not null
&& obj.getClass().equals(DetectedWebJar.class) // Check it's the right class
&& id.equals(((DetectedWebJar) obj).id); // Check id
}

/**
Expand Down

0 comments on commit 619072d

Please sign in to comment.