Fix problems found by static analysis.
Change-Id: I02c51279f18f629b2d2fb1095692a6ae98b0e25e
diff --git a/pom.xml b/pom.xml
index bd812b8..4bc3206 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,6 +31,7 @@
<basic-annotations.version>0.2.0</basic-annotations.version>
<findbugs-jsr305.version>3.0.2</findbugs-jsr305.version>
<flexmark.version>0.61.10</flexmark.version>
+ <google.java.format.version>1.7</google.java.format.version>
<hibernate.version>5.4.14.Final</hibernate.version>
<hibernate-types.version>2.9.8</hibernate-types.version>
<jakarta-jacc-api.version>1.6.1</jakarta-jacc-api.version>
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 @@
import java.io.Serializable;
import java.math.BigInteger;
+import java.util.Objects;
import javax.persistence.Column;
import javax.persistence.Id;
@@ -41,14 +42,10 @@
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.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 @@
@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 @@
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.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 @@
@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 @@
@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 @@
@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 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 @@
}
}
- 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.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 @@
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 @@
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 @@
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 @@
import java.io.Serializable;
import java.math.BigInteger;
+import java.util.Objects;
import javax.persistence.Column;
import javax.persistence.Id;
@@ -41,14 +42,10 @@
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 @@
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 @@
import java.io.Serializable;
import java.math.BigInteger;
+import java.util.Objects;
import javax.persistence.Column;
import javax.persistence.Id;
@@ -55,14 +56,10 @@
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 @@
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 @@
@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