summaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2020-04-18 20:44:07 +0200
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2020-04-18 20:44:07 +0200
commit593765de7fbd38c44f514363d0f3e0d4e82e6523 (patch)
tree79535b55a6d7df3d50ae2426a2183b27501ed214 /src/main/java
parent1e7674cf4880e21b24442c01914c2bcf9c00cb7b (diff)
Fix problems found by static analysis.
Change-Id: I02c51279f18f629b2d2fb1095692a6ae98b0e25e
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/accesscontrol/PageKeyPK.java9
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/bookmarks/BookmarkResource.java6
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatReferencePK.java6
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatResource.java10
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/posts/Post.java12
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java8
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/posts/PostTargetPK.java6
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/users/RsaKeyPK.java9
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/users/UserRolePK.java6
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/users/UserRsaKeyPK.java9
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiPageRevision.java4
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java8
12 files changed, 46 insertions, 47 deletions
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/accesscontrol/PageKeyPK.java b/src/main/java/eu/mulk/mulkcms2/benki/accesscontrol/PageKeyPK.java
index e80cb5e..f79686f 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/accesscontrol/PageKeyPK.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/accesscontrol/PageKeyPK.java
@@ -2,6 +2,7 @@ package eu.mulk.mulkcms2.benki.accesscontrol;
import java.io.Serializable;
import java.math.BigInteger;
+import java.util.Objects;
import javax.persistence.Column;
import javax.persistence.Id;
@@ -41,14 +42,10 @@ public class PageKeyPK implements Serializable {
PageKeyPK pageKeyPK = (PageKeyPK) o;
- if (page != null ? !page.equals(pageKeyPK.page) : pageKeyPK.page != null) {
+ if (!Objects.equals(page, pageKeyPK.page)) {
return false;
}
- if (key != null ? !key.equals(pageKeyPK.key) : pageKeyPK.key != null) {
- return false;
- }
-
- return true;
+ return Objects.equals(key, pageKeyPK.key);
}
@Override
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/BookmarkResource.java b/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/BookmarkResource.java
index 5ff8463..6dc76b0 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/BookmarkResource.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/BookmarkResource.java
@@ -1,7 +1,10 @@
package eu.mulk.mulkcms2.benki.bookmarks;
+import static javax.ws.rs.core.MediaType.APPLICATION_FORM_URLENCODED;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+import static javax.ws.rs.core.MediaType.MULTIPART_FORM_DATA;
import static javax.ws.rs.core.MediaType.TEXT_HTML;
+import static javax.ws.rs.core.MediaType.WILDCARD;
import eu.mulk.mulkcms2.benki.posts.Post;
import eu.mulk.mulkcms2.benki.posts.PostFilter;
@@ -22,6 +25,7 @@ import javax.json.JsonObject;
import javax.transaction.Transactional;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
+import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
@@ -45,6 +49,8 @@ public class BookmarkResource extends PostResource {
@POST
@Transactional
@Authenticated
+ @Produces(WILDCARD)
+ @Consumes({APPLICATION_FORM_URLENCODED, MULTIPART_FORM_DATA})
public Response postBookmark(
@FormParam("uri") @NotNull URI uri,
@FormParam("title") @NotEmpty String title,
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatReferencePK.java b/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatReferencePK.java
index 28ee2e0..20ff71c 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatReferencePK.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatReferencePK.java
@@ -43,11 +43,7 @@ public class LazychatReferencePK implements Serializable {
if (referrerId != that.referrerId) {
return false;
}
- if (refereeId != that.refereeId) {
- return false;
- }
-
- return true;
+ return refereeId == that.refereeId;
}
@Override
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatResource.java b/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatResource.java
index b919ad3..4f9a9fb 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatResource.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatResource.java
@@ -1,5 +1,9 @@
package eu.mulk.mulkcms2.benki.lazychat;
+import static javax.ws.rs.core.MediaType.APPLICATION_FORM_URLENCODED;
+import static javax.ws.rs.core.MediaType.MULTIPART_FORM_DATA;
+import static javax.ws.rs.core.MediaType.WILDCARD;
+
import eu.mulk.mulkcms2.benki.posts.Post;
import eu.mulk.mulkcms2.benki.posts.PostFilter;
import eu.mulk.mulkcms2.benki.posts.PostResource;
@@ -10,12 +14,14 @@ import java.time.OffsetDateTime;
import java.util.Objects;
import javax.transaction.Transactional;
import javax.validation.constraints.NotNull;
+import javax.ws.rs.Consumes;
import javax.ws.rs.ForbiddenException;
import javax.ws.rs.FormParam;
import javax.ws.rs.NotFoundException;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
@Path("/lazychat")
@@ -28,6 +34,8 @@ public class LazychatResource extends PostResource {
@POST
@Transactional
@Authenticated
+ @Produces(WILDCARD)
+ @Consumes({APPLICATION_FORM_URLENCODED, MULTIPART_FORM_DATA})
public Response postMessage(
@FormParam("text") @NotNull String text,
@FormParam("visibility") @NotNull Post.Visibility visibility)
@@ -51,6 +59,8 @@ public class LazychatResource extends PostResource {
@POST
@Transactional
@Authenticated
+ @Produces(WILDCARD)
+ @Consumes({APPLICATION_FORM_URLENCODED, MULTIPART_FORM_DATA})
@Path("{id}/edit")
public Response patchMessage(
@PathParam("id") int id,
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/posts/Post.java b/src/main/java/eu/mulk/mulkcms2/benki/posts/Post.java
index c402265..fc0f76f 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/posts/Post.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/posts/Post.java
@@ -42,7 +42,7 @@ import org.jboss.logging.Logger;
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class Post extends PanacheEntityBase {
- private static Logger log = Logger.getLogger(Post.class);
+ private static final Logger log = Logger.getLogger(Post.class);
@Id
@SequenceGenerator(
@@ -171,10 +171,10 @@ public abstract class Post extends PanacheEntityBase {
}
public static class PostPage<T extends Post> {
- public @CheckForNull Integer prevCursor;
- public @CheckForNull Integer cursor;
- public @CheckForNull Integer nextCursor;
- public List<T> posts;
+ public @CheckForNull final Integer prevCursor;
+ public @CheckForNull final Integer cursor;
+ public @CheckForNull final Integer nextCursor;
+ public final List<T> posts;
private PostPage(
@CheckForNull Integer c0,
@@ -259,7 +259,7 @@ public abstract class Post extends PanacheEntityBase {
}
}
- return new PostPage<T>(prevCursor, cursor, nextCursor, forwardResults);
+ return new PostPage<>(prevCursor, cursor, nextCursor, forwardResults);
}
public enum Visibility {
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java b/src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java
index 59bfb89..c718bbc 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java
@@ -28,6 +28,7 @@ import java.time.temporal.TemporalAccessor;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
+import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.CheckForNull;
@@ -169,6 +170,7 @@ public abstract class PostResource {
Date.from(
posts.stream()
.map(x -> x.date)
+ .filter(Objects::nonNull)
.max(Comparator.comparing(x -> x))
.orElse(OffsetDateTime.ofInstant(Instant.EPOCH, ZoneOffset.UTC))
.toInstant()));
@@ -192,8 +194,10 @@ public abstract class PostResource {
var entry = new Entry();
entry.setId(String.format("tag:%s,2012:/marx/%d", tagBase, post.id));
- entry.setPublished(Date.from(post.date.toInstant()));
- entry.setUpdated(Date.from(post.date.toInstant()));
+ if (post.date != null) {
+ entry.setPublished(Date.from(post.date.toInstant()));
+ entry.setUpdated(Date.from(post.date.toInstant()));
+ }
var author = new SyndPersonImpl();
author.setName(post.owner.getFirstAndLastName());
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/posts/PostTargetPK.java b/src/main/java/eu/mulk/mulkcms2/benki/posts/PostTargetPK.java
index ecd5861..e439ec9 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/posts/PostTargetPK.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/posts/PostTargetPK.java
@@ -43,11 +43,7 @@ public class PostTargetPK implements Serializable {
if (message != that.message) {
return false;
}
- if (targetId != that.targetId) {
- return false;
- }
-
- return true;
+ return targetId == that.targetId;
}
@Override
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/users/RsaKeyPK.java b/src/main/java/eu/mulk/mulkcms2/benki/users/RsaKeyPK.java
index 5b33ec8..83f4ced 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/users/RsaKeyPK.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/users/RsaKeyPK.java
@@ -2,6 +2,7 @@ package eu.mulk.mulkcms2.benki.users;
import java.io.Serializable;
import java.math.BigInteger;
+import java.util.Objects;
import javax.persistence.Column;
import javax.persistence.Id;
@@ -41,14 +42,10 @@ public class RsaKeyPK implements Serializable {
RsaKeyPK rsaKeyPK = (RsaKeyPK) o;
- if (modulus != null ? !modulus.equals(rsaKeyPK.modulus) : rsaKeyPK.modulus != null) {
+ if (!Objects.equals(modulus, rsaKeyPK.modulus)) {
return false;
}
- if (exponent != null ? !exponent.equals(rsaKeyPK.exponent) : rsaKeyPK.exponent != null) {
- return false;
- }
-
- return true;
+ return Objects.equals(exponent, rsaKeyPK.exponent);
}
@Override
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/users/UserRolePK.java b/src/main/java/eu/mulk/mulkcms2/benki/users/UserRolePK.java
index 5649ff4..aca126d 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/users/UserRolePK.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/users/UserRolePK.java
@@ -43,11 +43,7 @@ public class UserRolePK implements Serializable {
if (userId != that.userId) {
return false;
}
- if (roleId != that.roleId) {
- return false;
- }
-
- return true;
+ return roleId == that.roleId;
}
@Override
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/users/UserRsaKeyPK.java b/src/main/java/eu/mulk/mulkcms2/benki/users/UserRsaKeyPK.java
index adcaeb6..ef48c9a 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/users/UserRsaKeyPK.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/users/UserRsaKeyPK.java
@@ -2,6 +2,7 @@ package eu.mulk.mulkcms2.benki.users;
import java.io.Serializable;
import java.math.BigInteger;
+import java.util.Objects;
import javax.persistence.Column;
import javax.persistence.Id;
@@ -55,14 +56,10 @@ public class UserRsaKeyPK implements Serializable {
if (userId != that.userId) {
return false;
}
- if (modulus != null ? !modulus.equals(that.modulus) : that.modulus != null) {
+ if (!Objects.equals(modulus, that.modulus)) {
return false;
}
- if (exponent != null ? !exponent.equals(that.exponent) : that.exponent != null) {
- return false;
- }
-
- return true;
+ return Objects.equals(exponent, that.exponent);
}
@Override
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiPageRevision.java b/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiPageRevision.java
index df90421..161f371 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiPageRevision.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiPageRevision.java
@@ -95,10 +95,10 @@ public class WikiPageRevision extends PanacheEntityBase {
return soup;
}
- private static Pattern WIKIWORD_REGEX =
+ private static final Pattern WIKIWORD_REGEX =
Pattern.compile(
"\\p{javaUpperCase}+\\p{javaLowerCase}+\\p{javaUpperCase}+\\p{javaLowerCase}+\\w+");
- private static Pattern URL_REGEX =
+ private static final Pattern URL_REGEX =
Pattern.compile("\\(?\\bhttps?://[-A-Za-z0-9+&@#/%?=~_()|!:,.;]*[-A-Za-z0-9+&@#/%=~_()|]");
private static Document hrefify(Document soup) {
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java b/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java
index 5ed5dff..2ffcdd5 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java
@@ -39,14 +39,14 @@ import org.jsoup.safety.Whitelist;
@Path("/wiki")
public class WikiResource {
- private static Logger log = Logger.getLogger(WikiResource.class);
+ private static final Logger log = Logger.getLogger(WikiResource.class);
- private static DateTimeFormatter htmlDateFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
+ private static final DateTimeFormatter htmlDateFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
- private static DateTimeFormatter humanDateFormatter =
+ private static final DateTimeFormatter humanDateFormatter =
DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG, FormatStyle.SHORT);
- private static JsonProvider jsonProvider = JsonProvider.provider();
+ private static final JsonProvider jsonProvider = JsonProvider.provider();
@ResourcePath("benki/wiki/wikiPage.html")
@Inject