From 59987c0cdf71bb2b58e0b97abe60e5d77e3cd8be Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 17 Sep 2013 22:54:32 +0200 Subject: [PATCH] Fix some FindBugs warnings. --- pom.xml | 5 +++++ src/main/java/net/pterodactylus/sone/data/Album.java | 10 +++++++++- src/main/java/net/pterodactylus/sone/data/Identified.java | 5 ++++- src/main/java/net/pterodactylus/sone/data/Post.java | 2 +- src/main/java/net/pterodactylus/sone/data/PostReply.java | 2 +- src/main/java/net/pterodactylus/sone/data/Reply.java | 2 +- src/main/java/net/pterodactylus/sone/data/Sone.java | 6 +++--- src/main/java/net/pterodactylus/sone/web/SearchPage.java | 2 +- 8 files changed, 25 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index 6842c8a..9636143 100644 --- a/pom.xml +++ b/pom.xml @@ -53,6 +53,11 @@ jackson-databind 2.1.2 + + com.google.code.findbugs + jsr305 + 2.0.1 + diff --git a/src/main/java/net/pterodactylus/sone/data/Album.java b/src/main/java/net/pterodactylus/sone/data/Album.java index 8238b3f..70478f3 100644 --- a/src/main/java/net/pterodactylus/sone/data/Album.java +++ b/src/main/java/net/pterodactylus/sone/data/Album.java @@ -21,13 +21,16 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; import static java.util.Arrays.asList; +import static java.util.Collections.emptyList; import java.util.ArrayList; +import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; +import javax.annotation.Nonnull; import com.google.common.base.Function; import com.google.common.base.Optional; @@ -59,7 +62,11 @@ public class Album implements Identified, Fingerprintable { public static final Function> FLATTENER = new Function>() { @Override + @Nonnull public List apply(Album album) { + if (album == null) { + return emptyList(); + } List albums = new ArrayList(); albums.add(album); for (Album subAlbum : album.getAlbums()) { @@ -73,8 +80,9 @@ public class Album implements Identified, Fingerprintable { public static final Function> IMAGES = new Function>() { @Override + @Nonnull public List apply(Album album) { - return album.getImages(); + return (album != null) ? album.getImages() : Collections.emptyList(); } }; diff --git a/src/main/java/net/pterodactylus/sone/data/Identified.java b/src/main/java/net/pterodactylus/sone/data/Identified.java index f12f842..4892479 100644 --- a/src/main/java/net/pterodactylus/sone/data/Identified.java +++ b/src/main/java/net/pterodactylus/sone/data/Identified.java @@ -17,6 +17,8 @@ package net.pterodactylus.sone.data; +import javax.annotation.Nonnull; + import com.google.common.base.Function; import com.google.common.base.Optional; @@ -31,8 +33,9 @@ public interface Identified { public static final Function, Optional> GET_ID = new Function, Optional>() { @Override + @Nonnull public Optional apply(Optional identified) { - return identified.isPresent() ? Optional.of(identified.get().getId()) : Optional.absent(); + return (identified == null) ? Optional.absent() : (identified.isPresent() ? Optional.of(identified.get().getId()) : Optional.absent()); } }; diff --git a/src/main/java/net/pterodactylus/sone/data/Post.java b/src/main/java/net/pterodactylus/sone/data/Post.java index 2524207..759a8ba 100644 --- a/src/main/java/net/pterodactylus/sone/data/Post.java +++ b/src/main/java/net/pterodactylus/sone/data/Post.java @@ -45,7 +45,7 @@ public interface Post extends Identified { @Override public boolean apply(Post post) { - return post.getTime() <= System.currentTimeMillis(); + return (post == null) ? false : post.getTime() <= System.currentTimeMillis(); } }; diff --git a/src/main/java/net/pterodactylus/sone/data/PostReply.java b/src/main/java/net/pterodactylus/sone/data/PostReply.java index 1e870b9..4a1fbad 100644 --- a/src/main/java/net/pterodactylus/sone/data/PostReply.java +++ b/src/main/java/net/pterodactylus/sone/data/PostReply.java @@ -36,7 +36,7 @@ public interface PostReply extends Reply { @Override public boolean apply(PostReply postReply) { - return postReply.getPost().isPresent(); + return (postReply == null) ? false : postReply.getPost().isPresent(); } }; diff --git a/src/main/java/net/pterodactylus/sone/data/Reply.java b/src/main/java/net/pterodactylus/sone/data/Reply.java index 60e5eeb..c229d04 100644 --- a/src/main/java/net/pterodactylus/sone/data/Reply.java +++ b/src/main/java/net/pterodactylus/sone/data/Reply.java @@ -51,7 +51,7 @@ public interface Reply> extends Identified { */ @Override public boolean apply(Reply reply) { - return reply.getTime() <= System.currentTimeMillis(); + return (reply == null) ? false : reply.getTime() <= System.currentTimeMillis(); } }; diff --git a/src/main/java/net/pterodactylus/sone/data/Sone.java b/src/main/java/net/pterodactylus/sone/data/Sone.java index 8b15720..0415ecd 100644 --- a/src/main/java/net/pterodactylus/sone/data/Sone.java +++ b/src/main/java/net/pterodactylus/sone/data/Sone.java @@ -155,7 +155,7 @@ public class Sone implements Identified, Fingerprintable, Comparable { @Override public boolean apply(Sone sone) { - return sone.getTime() != 0; + return (sone == null) ? false : sone.getTime() != 0; } }; @@ -164,7 +164,7 @@ public class Sone implements Identified, Fingerprintable, Comparable { @Override public boolean apply(Sone sone) { - return sone.getIdentity() instanceof OwnIdentity; + return (sone == null) ? false : sone.getIdentity() instanceof OwnIdentity; } }; @@ -174,7 +174,7 @@ public class Sone implements Identified, Fingerprintable, Comparable { @Override public boolean apply(Sone sone) { - return !sone.getRootAlbum().getAlbums().isEmpty(); + return (sone == null) ? false : !sone.getRootAlbum().getAlbums().isEmpty(); } }; diff --git a/src/main/java/net/pterodactylus/sone/web/SearchPage.java b/src/main/java/net/pterodactylus/sone/web/SearchPage.java index 6c9e15c..e9241a1 100644 --- a/src/main/java/net/pterodactylus/sone/web/SearchPage.java +++ b/src/main/java/net/pterodactylus/sone/web/SearchPage.java @@ -581,7 +581,7 @@ public class SearchPage extends SoneTemplatePage { @Override public boolean apply(Hit hit) { - return hit.getScore() > 0; + return (hit == null) ? false : hit.getScore() > 0; } }; -- 2.7.4