From 8c4824487e604d2538f14e8f7ff5ada5782c9582 Mon Sep 17 00:00:00 2001 From: Scott Leberknight <174812+sleberknight@users.noreply.github.com> Date: Fri, 9 Aug 2024 14:42:32 -0400 Subject: [PATCH] Add "not null" annotations to KiwiResources#verifyExistence methods (#1181) Make it clear to all code analysis tools that the return value of the verifyExistence methods that accept an Optional can never return null; they either return a value or throw an exception. Closes #1167 --- src/main/java/org/kiwiproject/jaxrs/KiwiResources.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/org/kiwiproject/jaxrs/KiwiResources.java b/src/main/java/org/kiwiproject/jaxrs/KiwiResources.java index 8fa435eb..46b516ed 100644 --- a/src/main/java/org/kiwiproject/jaxrs/KiwiResources.java +++ b/src/main/java/org/kiwiproject/jaxrs/KiwiResources.java @@ -16,6 +16,7 @@ import jakarta.ws.rs.core.Response; import lombok.experimental.UtilityClass; import lombok.extern.slf4j.Slf4j; +import org.checkerframework.checker.nullness.qual.NonNull; import org.kiwiproject.base.KiwiStrings; import org.kiwiproject.jaxrs.exception.JaxrsBadRequestException; import org.kiwiproject.jaxrs.exception.JaxrsNotFoundException; @@ -67,6 +68,7 @@ public static void verifyExistence(T resourceEntity) { * @return the entity if the Optional contains a value * @throws JaxrsNotFoundException if the entity is empty */ + @NonNull public static T verifyExistence(Optional resourceEntity) { verifyExistence(resourceEntity.orElse(null), null); @@ -97,6 +99,7 @@ public static void verifyExistence(T resourceEntity, Class entityType, Ob * @return the entity if the Optional contains a value * @throws JaxrsNotFoundException if the entity is empty */ + @NonNull public static T verifyExistence(Optional resourceEntity, Class entityType, Object identifier) { var notFoundMessage = JaxrsNotFoundException.buildMessage(entityType.getSimpleName(), identifier); verifyExistence(resourceEntity.orElse(null), notFoundMessage); @@ -145,6 +148,7 @@ public static void verifyExistence(T resourceEntity, String notFoundMessageT * @return the entity if the Optional contains a value * @throws JaxrsNotFoundException if the entity is empty */ + @NonNull public static T verifyExistence(Optional resourceEntity, String notFoundMessage) { verifyExistence(resourceEntity.orElse(null), notFoundMessage); @@ -163,6 +167,7 @@ public static T verifyExistence(Optional resourceEntity, String notFoundM * @return the entity if the Optional contains a value * @throws JaxrsNotFoundException if the entity is empty */ + @NonNull public static T verifyExistence(Optional resourceEntity, String notFoundMessageTemplate, Object... args) { verifyExistence(resourceEntity.orElse(null), notFoundMessageTemplate, args);