From ca03ef4de62697217fe540504392efb0e2c44329 Mon Sep 17 00:00:00 2001 From: Anton Hansson Date: Sat, 8 Feb 2020 12:15:25 +0000 Subject: [PATCH] Add @Nullable and @NonNull to module API These two annotations are already in the public/system stubs, but are re-written to be package private instead of public. This makes them inaccessible to libs building against these stubs. When setting sdk_version:, the stubs of X will appear before any other libraries on the classpath. This also makes it impossible for modules to add Nullable annotations of their own when setting sdk_version. Exposing these annotations as public in the module stubs makes it possible for modules using these annotation to specify an sdk_version. Bug: 146758669 Test: m Test: downstream CLs using sdk_version:module_current Change-Id: I71fb766d02f833ed9a1b3a7dbfbc1c8118882b30 --- api/module-lib-current.txt | 10 ++++++++++ core/java/android/annotation/NonNull.java | 9 ++++++--- core/java/android/annotation/Nullable.java | 9 ++++++--- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/api/module-lib-current.txt b/api/module-lib-current.txt index 59aa145ce1e9b..e0e11208aa4ce 100644 --- a/api/module-lib-current.txt +++ b/api/module-lib-current.txt @@ -1,4 +1,14 @@ // Signature format: 2.0 +package android.annotation { + + @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.SOURCE) @java.lang.annotation.Target({java.lang.annotation.ElementType.METHOD, java.lang.annotation.ElementType.PARAMETER, java.lang.annotation.ElementType.FIELD}) public @interface NonNull { + } + + @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.SOURCE) @java.lang.annotation.Target({java.lang.annotation.ElementType.METHOD, java.lang.annotation.ElementType.PARAMETER, java.lang.annotation.ElementType.FIELD}) public @interface Nullable { + } + +} + package android.net { public final class TetheredClient implements android.os.Parcelable { diff --git a/core/java/android/annotation/NonNull.java b/core/java/android/annotation/NonNull.java index 927f9975b3ebc..a95bf3b8061e4 100644 --- a/core/java/android/annotation/NonNull.java +++ b/core/java/android/annotation/NonNull.java @@ -15,14 +15,16 @@ */ package android.annotation; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.PARAMETER; import static java.lang.annotation.RetentionPolicy.SOURCE; +import android.annotation.SystemApi.Client; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + /** * Denotes that a parameter, field or method return value can never be null. *

@@ -34,5 +36,6 @@ import static java.lang.annotation.RetentionPolicy.SOURCE; */ @Retention(SOURCE) @Target({METHOD, PARAMETER, FIELD}) +@SystemApi(client = Client.MODULE_LIBRARIES) public @interface NonNull { } diff --git a/core/java/android/annotation/Nullable.java b/core/java/android/annotation/Nullable.java index b60170b134e13..2fcddfab93758 100644 --- a/core/java/android/annotation/Nullable.java +++ b/core/java/android/annotation/Nullable.java @@ -15,14 +15,16 @@ */ package android.annotation; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.PARAMETER; import static java.lang.annotation.RetentionPolicy.SOURCE; +import android.annotation.SystemApi.Client; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + /** * Denotes that a parameter, field or method return value can be null. *

@@ -41,5 +43,6 @@ import static java.lang.annotation.RetentionPolicy.SOURCE; */ @Retention(SOURCE) @Target({METHOD, PARAMETER, FIELD}) +@SystemApi(client = Client.MODULE_LIBRARIES) public @interface Nullable { }