Turn on validation of nullability annotations for libcore.
This new target enforces that there are no broken annotations (e.g. on
primitive types) and that the missing annotations match the checked-in
warnings file.
This means that anyone checking in some new API surface in a class
which is otherwise annotated must either annotate it, or update the
checked-in warnings file. The latter option is as simple as making the
update target. (The error message contains these instructions.)
Bug: 73448108
Test: `make core-current-stubs-nullability-validation`
Test: `make core-current-stubs-nullability-validation-check-nullability-warnings`
Test: Change something, then `make core-current-stubs-nullability-validation-update-nullability-warnings`
Change-Id: I7ce044631ea144c83bd7ddefb9580bcb08b32a8b
diff --git a/JavaLibrary.bp b/JavaLibrary.bp
index 45bfba7..1a46d48 100644
--- a/JavaLibrary.bp
+++ b/JavaLibrary.bp
@@ -583,6 +583,10 @@
name: "ojluni-annotated-sdk-stubs",
path: "ojluni/annotations/sdk",
}
+droiddoc_exported_dir {
+ name: "ojluni-annotated-nullability-stubs",
+ path: "ojluni/annotations/sdk/nullability",
+}
// Exports annotated stubs source files in ojluni/annotations/mmodules to make
// them available to metalava. Used for core platform API and intra-code API
@@ -613,6 +617,31 @@
merge_inclusion_annotations_dirs: ["ojluni-annotated-mmodule-stubs"],
}
+// Target for validating nullability annotations for correctness and
+// completeness. To check that there are no nullability errors:
+// make core-current-stubs-nullability-validation
+// To check that there are only the expected nullability warnings:
+// make core-current-stubs-nullability-validation-check-nullability-warnings
+// To update the the list of known expected nullability warnings:
+// make core-current-stubs-nullability-validation-update-nullability-warnings
+droidstubs {
+ name: "core-current-stubs-nullability-validation",
+ srcs: [":core_api_files"],
+ installable: false,
+ no_framework_libs: true,
+ annotations_enabled: true,
+ args: "--hide-annotation libcore.api.Hide " +
+ "--validate-nullability-from-merged-stubs ",
+ merge_inclusion_annotations_dirs: ["ojluni-annotated-mmodule-stubs"],
+ merge_annotations_dirs: [
+ "metalava-manual",
+ // N.B. Stubs in this filegroup will be validated:
+ "ojluni-annotated-nullability-stubs",
+ ],
+ // The expected set of warnings about missing annotations:
+ check_nullability_warnings: "nullability_warnings.txt",
+}
+
// A stubs target containing the parts of the public SDK API provided by the
// core library.
//