From 288cbf4a80f24f1691e7cb62caa13eb3f2877c35 Mon Sep 17 00:00:00 2001 From: Chris Eager Date: Wed, 16 Feb 2022 11:22:59 -0800 Subject: [PATCH] Clean up null-ability of incoming message entity fields --- .../entities/IncomingMessage.java | 31 ++++++------------- .../entities/IncomingMessageList.java | 16 ++++------ .../controllers/MessageControllerTest.java | 3 +- 3 files changed, 18 insertions(+), 32 deletions(-) diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/entities/IncomingMessage.java b/service/src/main/java/org/whispersystems/textsecuregcm/entities/IncomingMessage.java index 3ddcc34c1..bd7ea6cfa 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/entities/IncomingMessage.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/entities/IncomingMessage.java @@ -10,16 +10,16 @@ import com.fasterxml.jackson.annotation.JsonProperty; public class IncomingMessage { @JsonProperty - private int type; + private final int type; @JsonProperty private final String destination; @JsonProperty - private long destinationDeviceId; + private final long destinationDeviceId; @JsonProperty - private int destinationRegistrationId; + private final int destinationRegistrationId; @JsonProperty private final String body; @@ -35,31 +35,20 @@ public class IncomingMessage { @JsonCreator public IncomingMessage( - @JsonProperty("id") final Integer type, + @JsonProperty("id") final int type, @JsonProperty("destination") final String destination, - @JsonProperty("destinationDeviceId") final Long destinationDeviceId, - @JsonProperty("destinationRegistrationId") final Integer destinationRegistrationId, + @JsonProperty("destinationDeviceId") final long destinationDeviceId, + @JsonProperty("destinationRegistrationId") final int destinationRegistrationId, @JsonProperty("body") final String body, @JsonProperty("content") final String content, - @JsonProperty("relay") final String relay, - @JsonProperty("timestamp") final Long timestamp) { - if (type != null) { - this.type = type; - } + @JsonProperty("relay") final String relay) { + this.type = type; this.destination = destination; - - if (destinationDeviceId != null) { - this.destinationDeviceId = destinationDeviceId; - } - if (destinationRegistrationId != null) { - this.destinationRegistrationId = destinationRegistrationId; - } + this.destinationDeviceId = destinationDeviceId; + this.destinationRegistrationId = destinationRegistrationId; this.body = body; this.content = content; this.relay = relay; - if (timestamp != null) { - this.timestamp = timestamp; - } } public String getDestination() { diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/entities/IncomingMessageList.java b/service/src/main/java/org/whispersystems/textsecuregcm/entities/IncomingMessageList.java index 555b59e92..6fe4523cb 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/entities/IncomingMessageList.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/entities/IncomingMessageList.java @@ -18,23 +18,19 @@ public class IncomingMessageList { private final List<@NotNull IncomingMessage> messages; @JsonProperty - private long timestamp; + private final long timestamp; @JsonProperty - private boolean online; + private final boolean online; @JsonCreator public IncomingMessageList( @JsonProperty("messages") final List<@NotNull IncomingMessage> messages, - @JsonProperty("online") final Boolean online, - @JsonProperty("timestamp") final Long timestamp) { + @JsonProperty("online") final boolean online, + @JsonProperty("timestamp") final long timestamp) { this.messages = messages; - if (timestamp != null) { - this.timestamp = timestamp; - } - if (online != null) { - this.online = online; - } + this.timestamp = timestamp; + this.online = online; } public List getMessages() { diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/controllers/MessageControllerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/controllers/MessageControllerTest.java index 2b9779442..1f355f908 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/controllers/MessageControllerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/controllers/MessageControllerTest.java @@ -646,7 +646,8 @@ class MessageControllerTest { try { return Stream.of( Entity.entity(new IncomingMessageList( - List.of(new IncomingMessage(1, null, 1L, null, new String(contentBytes), null, null, null)), null, null), + List.of(new IncomingMessage(1, null, 1L, 1, new String(contentBytes), null, null)), false, + System.currentTimeMillis()), MediaType.APPLICATION_JSON_TYPE), Entity.entity(messageStream.toByteArray(), MultiDeviceMessageListProvider.MEDIA_TYPE) );