Fix some FindBugs warnings.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 17 Sep 2013 20:54:32 +0000 (22:54 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 17 Sep 2013 20:54:32 +0000 (22:54 +0200)
pom.xml
src/main/java/net/pterodactylus/sone/data/Album.java
src/main/java/net/pterodactylus/sone/data/Identified.java
src/main/java/net/pterodactylus/sone/data/Post.java
src/main/java/net/pterodactylus/sone/data/PostReply.java
src/main/java/net/pterodactylus/sone/data/Reply.java
src/main/java/net/pterodactylus/sone/data/Sone.java
src/main/java/net/pterodactylus/sone/web/SearchPage.java

diff --git a/pom.xml b/pom.xml
index 6842c8a..9636143 100644 (file)
--- a/pom.xml
+++ b/pom.xml
                        <artifactId>jackson-databind</artifactId>
                        <version>2.1.2</version>
                </dependency>
+               <dependency>
+                       <groupId>com.google.code.findbugs</groupId>
+                       <artifactId>jsr305</artifactId>
+                       <version>2.0.1</version>
+               </dependency>
        </dependencies>
        <repositories>
                <repository>
index 8238b3f..70478f3 100644 (file)
@@ -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<Album, List<Album>> FLATTENER = new Function<Album, List<Album>>() {
 
                @Override
+               @Nonnull
                public List<Album> apply(Album album) {
+                       if (album == null) {
+                               return emptyList();
+                       }
                        List<Album> albums = new ArrayList<Album>();
                        albums.add(album);
                        for (Album subAlbum : album.getAlbums()) {
@@ -73,8 +80,9 @@ public class Album implements Identified, Fingerprintable {
        public static final Function<Album, List<Image>> IMAGES = new Function<Album, List<Image>>() {
 
                @Override
+               @Nonnull
                public List<Image> apply(Album album) {
-                       return album.getImages();
+                       return (album != null) ? album.getImages() : Collections.<Image>emptyList();
                }
        };
 
index f12f842..4892479 100644 (file)
@@ -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<? extends Identified>, Optional<String>> GET_ID = new Function<Optional<? extends Identified>, Optional<String>>() {
 
                @Override
+               @Nonnull
                public Optional<String> apply(Optional<? extends Identified> identified) {
-                       return identified.isPresent() ? Optional.of(identified.get().getId()) : Optional.<String>absent();
+                       return (identified == null) ? Optional.<String>absent() : (identified.isPresent() ? Optional.of(identified.get().getId()) : Optional.<String>absent());
                }
        };
 
index 2524207..759a8ba 100644 (file)
@@ -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();
                }
 
        };
index 1e870b9..4a1fbad 100644 (file)
@@ -36,7 +36,7 @@ public interface PostReply extends Reply<PostReply> {
 
                @Override
                public boolean apply(PostReply postReply) {
-                       return postReply.getPost().isPresent();
+                       return (postReply == null) ? false : postReply.getPost().isPresent();
                }
        };
 
index 60e5eeb..c229d04 100644 (file)
@@ -51,7 +51,7 @@ public interface Reply<T extends Reply<T>> extends Identified {
                 */
                @Override
                public boolean apply(Reply<?> reply) {
-                       return reply.getTime() <= System.currentTimeMillis();
+                       return (reply == null) ? false : reply.getTime() <= System.currentTimeMillis();
                }
 
        };
index 8b15720..0415ecd 100644 (file)
@@ -155,7 +155,7 @@ public class Sone implements Identified, Fingerprintable, Comparable<Sone> {
 
                @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<Sone> {
 
                @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<Sone> {
 
                @Override
                public boolean apply(Sone sone) {
-                       return !sone.getRootAlbum().getAlbums().isEmpty();
+                       return (sone == null) ? false : !sone.getRootAlbum().getAlbums().isEmpty();
                }
        };
 
index 6c9e15c..e9241a1 100644 (file)
@@ -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;
                        }
 
                };