From 12b3928ad89d4ecb65c237384bc9f1a5f6cb377a Mon Sep 17 00:00:00 2001 From: Stephen Crawford Date: Thu, 20 Apr 2023 11:16:00 -0400 Subject: [PATCH] add annotation Signed-off-by: Stephen Crawford --- .../java/org/opensearch/common/NotNull.java | 32 +++++++++++++++++++ server/build.gradle | 2 ++ .../opensearch/plugins/IdentityPlugin.java | 4 +-- 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 libs/common/src/main/java/org/opensearch/common/NotNull.java diff --git a/libs/common/src/main/java/org/opensearch/common/NotNull.java b/libs/common/src/main/java/org/opensearch/common/NotNull.java new file mode 100644 index 0000000000000..ecbd2851291ae --- /dev/null +++ b/libs/common/src/main/java/org/opensearch/common/NotNull.java @@ -0,0 +1,32 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.common; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import javax.annotation.Nonnull; +import javax.annotation.meta.TypeQualifierNickname; + +/** + * The presence of this annotation on a method indicates that + * {@code null} will not be returned from that method. + * + * @opensearch.api + */ +@Documented +@TypeQualifierNickname +@Nonnull +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.METHOD }) +public @interface NotNull { +} + diff --git a/server/build.gradle b/server/build.gradle index 2eea312699798..b9e2b88b4532c 100644 --- a/server/build.gradle +++ b/server/build.gradle @@ -92,6 +92,8 @@ dependencies { api project(':libs:opensearch-secure-sm') api project(':libs:opensearch-x-content') api project(":libs:opensearch-geo") + implementation 'org.jetbrains:annotations:23.0.0' + implementation 'org.jetbrains:annotations:23.0.0' compileOnly project(':libs:opensearch-plugin-classloader') testRuntimeOnly project(':libs:opensearch-plugin-classloader') diff --git a/server/src/main/java/org/opensearch/plugins/IdentityPlugin.java b/server/src/main/java/org/opensearch/plugins/IdentityPlugin.java index 7246720cba3aa..924d45243faea 100644 --- a/server/src/main/java/org/opensearch/plugins/IdentityPlugin.java +++ b/server/src/main/java/org/opensearch/plugins/IdentityPlugin.java @@ -8,7 +8,7 @@ package org.opensearch.plugins; -import org.opensearch.common.Nullable; +import org.opensearch.common.NotNull; import org.opensearch.identity.Subject; /** @@ -21,6 +21,6 @@ public interface IdentityPlugin { /** * Get the current subject * */ - @Nullable + @NotNull public Subject getSubject(); }