From ba5e5a780fc8aef287ecd7249322a3d99db6d723 Mon Sep 17 00:00:00 2001 From: Chris Eager Date: Tue, 15 Feb 2022 17:46:27 -0800 Subject: [PATCH] Throw an exception instead of using Optional --- .../textsecuregcm/controllers/MessageController.java | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/MessageController.java b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/MessageController.java index a4457c92f..0b8e07ca5 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/MessageController.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/MessageController.java @@ -202,12 +202,7 @@ public class MessageController { contentLength += message.getBody().length(); } - Optional maybeResponse = validateContentLength(contentLength, userAgent); - - if (maybeResponse.isPresent()) { - return maybeResponse.get(); - } - + validateContentLength(contentLength, userAgent); validateEnvelopeType(message.getType(), userAgent); } @@ -778,17 +773,16 @@ public class MessageController { } } - private Optional validateContentLength(final int contentLength, final String userAgent) { + private void validateContentLength(final int contentLength, final String userAgent) { Metrics.summary(CONTENT_SIZE_DISTRIBUTION_NAME, Tags.of(UserAgentTagUtil.getPlatformTag(userAgent))) .record(contentLength); if (contentLength > MAX_MESSAGE_SIZE) { Metrics.counter(REJECT_OVERSIZE_MESSAGE_COUNTER, Tags.of(UserAgentTagUtil.getPlatformTag(userAgent))) .increment(); - return Optional.of(Response.status(Status.REQUEST_ENTITY_TOO_LARGE).build()); + throw new WebApplicationException(Status.REQUEST_ENTITY_TOO_LARGE); } - return Optional.empty(); } private void validateEnvelopeType(final int type, final String userAgent) {