Skip to content

Commit

Permalink
Recognize some experimental Google-internal protobuf annotations.
Browse files Browse the repository at this point in the history
While there, reorganize the two nullness-annotation regexes to make them better parallel one another.

PiperOrigin-RevId: 447977257
  • Loading branch information
cpovirk authored and Error Prone Team committed May 11, 2022
1 parent d14a43b commit 9ca78df
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,19 @@ public class NullnessAnnotations {
// TODO(kmb): Correctly handle JSR 305 @Nonnull(NEVER) etc.
private static final Predicate<String> ANNOTATION_RELEVANT_TO_NULLNESS =
Pattern.compile(
".*\\b((Recently)?Nullable(Decl|Type)?|(Recently)?NotNull|NonNull(Decl|Type)?|"
+ "Nonnull|CheckForNull|PolyNull|MonotonicNonNull(Decl)?)$")
".*\\b("
+ "(Recently)?NotNull|NonNull(Decl|Type)?|Nonnull|"
+ "(Recently)?Nullable(Decl|Type)?|CheckForNull|PolyNull|MonotonicNonNull(Decl)?|"
+ "ProtoMethodMayReturnNull|ProtoMethodAcceptsNullParameter|"
+ "ProtoPassThroughNullness"
+ ")$")
.asPredicate();
private static final Predicate<String> NULLABLE_ANNOTATION =
Pattern.compile(
".*\\b("
+ "(Recently)?Nullable(Decl|Type)?|CheckForNull|PolyNull|MonotonicNonNull(Decl)?"
+ "(Recently)?Nullable(Decl|Type)?|CheckForNull|PolyNull|MonotonicNonNull(Decl)?|"
+ "ProtoMethodMayReturnNull|ProtoMethodAcceptsNullParameter|"
+ "ProtoPassThroughNullness"
+ ")$")
.asPredicate();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ public void testNegativeAlreadyAnnotated() {
.doTest();
}

@Test
public void testNegativeAlreadyAnnotatedWithProtobufAnnotation() {
aggressiveHelper
.addSourceLines(
"ProtoMethodAcceptsNullParameter.java", "@interface ProtoMethodAcceptsNullParameter {}")
.addSourceLines(
"Foo.java",
"abstract class Foo {",
" public abstract boolean equals(@ProtoMethodAcceptsNullParameter Object o);",
"}")
.doTest();
}

@Test
public void testNegativeNotObjectEquals() {
aggressiveHelper
Expand Down

0 comments on commit 9ca78df

Please sign in to comment.