From 8d9f50c68af853b227a13f182589805292a1c9aa Mon Sep 17 00:00:00 2001 From: Chris Povirk Date: Thu, 13 Jan 2022 20:36:54 -0500 Subject: [PATCH] Recognize an experimental protobuf @PolyNull annotation (#147) Co-authored-by: Werner Dietl --- .../NullnessAnnotatedTypeFactory.java | 12 +++++++++ docs/manual/nullness-checker.tex | 26 +++++++++++++++++-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/checker/src/main/java/org/checkerframework/checker/nullness/NullnessAnnotatedTypeFactory.java b/checker/src/main/java/org/checkerframework/checker/nullness/NullnessAnnotatedTypeFactory.java index cbcaeb94480..947b1595e49 100644 --- a/checker/src/main/java/org/checkerframework/checker/nullness/NullnessAnnotatedTypeFactory.java +++ b/checker/src/main/java/org/checkerframework/checker/nullness/NullnessAnnotatedTypeFactory.java @@ -299,6 +299,17 @@ public class NullnessAnnotatedTypeFactory // https://github.com/reactor/reactor-core/blob/main/reactor-core/src/main/java/reactor/util/annotation/Nullable.java "reactor.util.annotation.Nullable"); + // List is in alphabetical order. If you update it, also update + // ../../../../../../../../docs/manual/nullness-checker.tex . + // See more comments with NONNULL_ALIASES above. + /** Aliases for {@code @PolyNull}. */ + @SuppressWarnings( + "signature:assignment.type.incompatible") // Class names intentionally obfuscated + private static final List<@FullyQualifiedName String> POLYNULL_ALIASES = + Arrays.asList( + // "com.google.protobuf.Internal.ProtoPassThroughNullness", + "com.go".toString() + "ogle.protobuf.Internal.ProtoPassThroughNullness"); + /** * Creates a NullnessAnnotatedTypeFactory. * @@ -316,6 +327,7 @@ public NullnessAnnotatedTypeFactory(BaseTypeChecker checker) { NONNULL_ALIASES.forEach(annotation -> addAliasedTypeAnnotation(annotation, NONNULL)); NULLABLE_ALIASES.forEach(annotation -> addAliasedTypeAnnotation(annotation, NULLABLE)); + POLYNULL_ALIASES.forEach(annotation -> addAliasedTypeAnnotation(annotation, POLYNULL)); // Add compatibility annotations: addAliasedTypeAnnotation( diff --git a/docs/manual/nullness-checker.tex b/docs/manual/nullness-checker.tex index 3454b1f405b..12ac7033a8f 100644 --- a/docs/manual/nullness-checker.tex +++ b/docs/manual/nullness-checker.tex @@ -915,8 +915,9 @@ annotation, the Checker Framework can type-check your code. It treats annotations from other tools as if you had written the corresponding annotation from the -Nullness Checker, as described in Figures~\ref{fig-nullness-refactoring-nonnull} -and \ref{fig-nullness-refactoring-nullable}. +Nullness Checker, as described in Figures~\ref{fig-nullness-refactoring-nonnull}, +\ref{fig-nullness-refactoring-nullable}, and +\ref{fig-nullness-refactoring-polynull}. If the other annotation is a declaration annotation, it may be moved; see Section~\ref{declaration-annotations-moved}. @@ -1046,6 +1047,27 @@ \label{fig-nullness-refactoring-nullable} \end{figure} +% See comments above previous table. +\begin{figure} +\begin{center} +\begin{tabular}{ll} +\begin{tabular}{|l|l|} +\hline + ~com.google.protobuf.Internal.ProtoPassThroughNullness~ \\ \hline +\end{tabular} +& +$\Rightarrow$ +~org.checkerframework.checker.nullness.qual.PolyNull~ +\end{tabular} +\end{center} +%BEGIN LATEX +\vspace{-1.5\baselineskip} +%END LATEX +\caption{Correspondence between other nullness annotations and the + Checker Framework's \ annotation.} +\label{fig-nullness-refactoring-polynull} +\end{figure} + %% Removed, because it's tedious and should be obvious to a decent programmer. % Your IDE may be able to do that for you. Alternately, do the following: % \begin{enumerate}