Skip to content

Commit

Permalink
Upgrade JSpecify 0.2.0 -> 0.3.0
Browse files Browse the repository at this point in the history
The removed `org.jspecify.nullness` package is still supported where
possible, but `NullnessUtils#pickNullableAnnotation` now falls back to
suggesting `org.jspecify.annotations.Nullable`.

See:
- https://github.com/jspecify/jspecify/releases/tag/v0.3.0-alpha-1
- https://github.com/jspecify/jspecify/releases/tag/v0.3.0-alpha-2
- https://github.com/jspecify/jspecify/releases/tag/v0.3.0-alpha-3
- https://github.com/jspecify/jspecify/releases/tag/v0.3.0
- jspecify/jspecify@v0.2.0...v0.3.0

Fixes #4059

RELNOTES=n/a
PiperOrigin-RevId: 562772958
  • Loading branch information
Stephan202 authored and Error Prone Team committed Sep 6, 2023
1 parent d546886 commit 9a427bf
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,9 @@ private boolean enclosingAnnotationDefaultsNonTypeVariablesToNonNull(
if (hasAnnotation(sym, "com.google.protobuf.Internal$ProtoNonnullApi", state)) {
return true;
}
if (hasAnnotation(sym, "org.jspecify.nullness.NullMarked", state)
if ((hasAnnotation(sym, "org.jspecify.annotations.NullMarked", state)
// We break this string to avoid having it rewritten by Copybara.
|| hasAnnotation(sym, "org.jspecify.null" + "ness.NullMarked", state))
&& weTrustNullMarkedOn(sym, state)) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ static boolean nullnessChecksShouldBeConservative(ErrorProneFlags flags) {

static boolean isInNullMarkedScope(Symbol sym, VisitorState state) {
for (; sym != null; sym = sym.getEnclosingElement()) {
if (hasAnnotation(sym, "org.jspecify.nullness.NullMarked", state)) {
if (hasAnnotation(sym, "org.jspecify.annotations.NullMarked", state)
// We break this string to avoid having it rewritten by Copybara.
|| hasAnnotation(sym, "org.jspecify.null" + "ness.NullMarked", state)) {
return true;
}
}
Expand Down Expand Up @@ -353,7 +355,7 @@ private static NullableAnnotationToUse pickNullableAnnotation(VisitorState state
.orElse(
state.isAndroidCompatible()
? "androidx.annotation.Nullable"
: "org.jspecify.nullness.Nullable");
: "org.jspecify.annotations.Nullable");
if (sym != null) {
ClassSymbol classSym = (ClassSymbol) sym;
if (classSym.isAnnotationType()) {
Expand Down Expand Up @@ -381,8 +383,9 @@ private static boolean isTypeUse(String className) {
case "org.checkerframework.checker.nullness.qual.Nullable":
case "org.jspecify.annotations.NonNull":
case "org.jspecify.annotations.Nullable":
case "org.jspecify.nullness.NonNull":
case "org.jspecify.nullness.Nullable":
// We break these strings to avoid having them rewritten by Copybara.
case "org.jspecify.null" + "ness.NonNull":
case "org.jspecify.null" + "ness.Nullable":
return true;
default:
// TODO(cpovirk): Detect type-use-ness from the class symbol if it's available?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void methodReturnsOptionalWithAnotherNullableAnnotation_showsError() {
.addSourceLines(
"Test.java",
"import java.util.Optional;",
"import org.jspecify.nullness.Nullable;",
"import org.jspecify.annotations.Nullable;",
"final class Test {",
" @Nullable",
" // BUG: Diagnostic contains:",
Expand Down Expand Up @@ -136,7 +136,7 @@ public void methodReturnsNonOptionalWithAnotherNullableAnnotation_noError() {
compilationHelper
.addSourceLines(
"Test.java",
"import org.jspecify.nullness.Nullable;",
"import org.jspecify.annotations.Nullable;",
"final class Test {",
" @Nullable",
" private Object foo() {",
Expand All @@ -151,7 +151,7 @@ public void methodHasNullableNonOptionalAsParameter_noError() {
compilationHelper
.addSourceLines(
"Test.java",
"import org.jspecify.nullness.Nullable;",
"import org.jspecify.annotations.Nullable;",
"final class Test {",
" private void foo(@Nullable Object object) {}",
"}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void positiveConservativeNullMarked() {
conservativeHelper
.addSourceLines(
"Foo.java",
"import org.jspecify.nullness.NullMarked;",
"import org.jspecify.annotations.NullMarked;",
"@NullMarked",
"abstract class Foo {",
" // BUG: Diagnostic contains: @Nullable",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ public void nonAnnotationNullable() {
.addOutputLines(
"out/Test.java",
"class T {",
" private final @org.jspecify.nullness.Nullable Object obj2 = null;",
" private final @org.jspecify.annotations.Nullable Object obj2 = null;",
" class Nullable {}",
"}")
.doTest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public void positiveNullMarkedOtherPackageAggressive() {
aggressiveHelper
.addSourceLines(
"Foo.java",
"import org.jspecify.nullness.NullMarked;",
"import org.jspecify.annotations.NullMarked;",
"@NullMarked",
"class Foo {",
" void consume(String s) {}",
Expand All @@ -194,7 +194,7 @@ public void negativeNullMarkedNonComGoogleCommonPackageConservative() {
conservativeHelper
.addSourceLines(
"Foo.java",
"import org.jspecify.nullness.NullMarked;",
"import org.jspecify.annotations.NullMarked;",
"@NullMarked",
"class Foo {",
" void consume(String s) {}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ public void removeSuppressWarnings_removeNullnessReturnWarning() {
.addOutputLines(
"com/google/errorprone/bugpatterns/nullness/LiteralNullReturnTest.java",
"package com.google.errorprone.bugpatterns.nullness;",
"import org.jspecify.nullness.Nullable;",
"import org.jspecify.annotations.Nullable;",
"public class LiteralNullReturnTest {",
"",
" public @Nullable String getMessage(boolean b) {",
Expand Down Expand Up @@ -1689,8 +1689,8 @@ public void nonAnnotationNullable() {
.addOutputLines(
"out/Test.java",
"class T {",
" @org.jspecify.nullness.Nullable private final Object method(boolean b) { return b ?"
+ " null : 0; }",
" @org.jspecify.annotations.Nullable private final Object method(boolean b) { return b"
+ " ? null : 0; }",
" class Nullable {}",
"}")
.doTest();
Expand All @@ -1712,7 +1712,7 @@ public void multipleNullReturns() {
"}")
.addOutputLines(
"out/Test.java",
"import org.jspecify.nullness.Nullable;",
"import org.jspecify.annotations.Nullable;",
"class T {",
" private final @Nullable Object method(boolean b) {",
" if (b) {",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ public void positiveConservativeNullMarked() {
.addSourceLines(
"Test.java",
"import javax.annotation.Nullable;",
"import org.jspecify.nullness.NullMarked;",
"import org.jspecify.annotations.NullMarked;",
"@NullMarked",
"class Test {",
" // BUG: Diagnostic contains: @Nullable",
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<nexus-staging-maven-plugin.version>1.6.13</nexus-staging-maven-plugin.version>
<protobuf.version>3.19.6</protobuf.version>
<grpc.version>1.43.3</grpc.version>
<jspecify.version>0.2.0</jspecify.version>
<jspecify.version>0.3.0</jspecify.version>
<guice.version>5.1.0</guice.version>
</properties>

Expand Down

0 comments on commit 9a427bf

Please sign in to comment.