Skip to content

Commit

Permalink
Update to JSpecify 0.3.0-alpha-1 (#673)
Browse files Browse the repository at this point in the history
The artifact now contains `@NullMarked` and `@NullUnmarked` annotations, so we do not need to create our own copies for testing.  We leverage the Error Prone javac to keep builds working on JDK 8; this is a workaround for jspecify/jspecify#302
  • Loading branch information
msridhar committed Nov 14, 2022
1 parent b8dde69 commit 3da177a
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 170 deletions.
20 changes: 12 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ subprojects { project ->
}
project.tasks.withType(JavaCompile) {
dependsOn(installGitHooks)
options.compilerArgs += [
"-Xlint:deprecation",
"-Xlint:rawtypes",
"-Xlint:unchecked",
"-Werror"
]
if (JavaVersion.current().isJava9Compatible()) {
options.compilerArgs += [
"-Xlint:deprecation",
"-Xlint:rawtypes",
"-Xlint:unchecked",
"-Werror"
]
options.errorprone {
// disable warnings in generated code; AutoValue code fails UnnecessaryParentheses check
disableWarningsInGeneratedCode = true
Expand All @@ -77,8 +77,12 @@ subprojects { project ->
check("SymbolToString", CheckSeverity.ERROR)
}
} else {
// disable Error Prone checking of our code on JDK 8, as more recent versions don't run on JDK 8
options.errorprone.enabled = false
// Disable Error Prone checks on JDK 8, as more recent Error Prone versions don't run on JDK 8
// NOTE: we use disableAllChecks rather than the enabled flag because we still want to use the
// JDK 9 javac packaged with Error Prone, to work around the following bug with JDK 8 javac
// and use of the @NullMarked / @NullUnmarked annotations from jspecify:
// https://github.com/jspecify/jspecify/issues/302
options.errorprone.disableAllChecks = true
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def build = [
checkerDataflow : "org.checkerframework:dataflow-nullaway:${versions.checkerFramework}",
guava : "com.google.guava:guava:24.1.1-jre",
javaxValidation : "javax.validation:validation-api:2.0.1.Final",
jspecify : "org.jspecify:jspecify:0.2.0",
jspecify : "org.jspecify:jspecify:0.3.0-alpha-1",
jsr305Annotations : "com.google.code.findbugs:jsr305:3.0.2",
commonsIO : "commons-io:commons-io:2.11.0",
wala : ["com.ibm.wala:com.ibm.wala.util:${versions.wala}",
Expand Down
50 changes: 25 additions & 25 deletions nullaway/src/test/java/com/uber/nullaway/NullAwayJSpecifyTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public void nullMarkedMethodLevel() {
.addSourceLines(
"Foo.java",
"package com.example.thirdparty;",
"import com.example.jspecify.future.annotations.NullMarked;",
"import org.jspecify.nullness.NullMarked;",
"public class Foo {",
" @NullMarked",
" public static String foo(String s) {",
Expand Down Expand Up @@ -268,7 +268,7 @@ public void nullMarkedMethodLevelScan() {
.addSourceLines(
"Foo.java",
"package com.example.thirdparty;",
"import com.example.jspecify.future.annotations.NullMarked;",
"import org.jspecify.nullness.NullMarked;",
"public class Foo {",
" @NullMarked",
" public static String foo(String s) {",
Expand All @@ -278,7 +278,7 @@ public void nullMarkedMethodLevelScan() {
.addSourceLines(
"Bar.java",
"package com.example.thirdparty;",
"import com.example.jspecify.future.annotations.NullMarked;",
"import org.jspecify.nullness.NullMarked;",
"public class Bar {",
" public static void bar1() {",
" // No report, unannotated caller!",
Expand All @@ -299,7 +299,7 @@ public void nullMarkedOuterMethodLevelWithAnonymousClass() {
.addSourceLines(
"Foo.java",
"package com.example.thirdparty;",
"import com.example.jspecify.future.annotations.NullMarked;",
"import org.jspecify.nullness.NullMarked;",
"public class Foo {",
" @NullMarked",
" public static String foo(String s) {",
Expand All @@ -309,7 +309,7 @@ public void nullMarkedOuterMethodLevelWithAnonymousClass() {
.addSourceLines(
"Bar.java",
"package com.example.thirdparty;",
"import com.example.jspecify.future.annotations.NullMarked;",
"import org.jspecify.nullness.NullMarked;",
"public class Bar {",
" @NullMarked",
" public static Runnable runFoo() {",
Expand All @@ -336,7 +336,7 @@ public void nullMarkedOuterMethodLevelUsage() {
.addSourceLines(
"Foo.java",
"package com.example.thirdparty;",
"import com.example.jspecify.future.annotations.NullMarked;",
"import org.jspecify.nullness.NullMarked;",
"public class Foo {",
" @NullMarked",
" public static IConsumer getConsumer() {",
Expand Down Expand Up @@ -367,7 +367,7 @@ public void nullMarkedOuterMethodLevelWithLocalClass() {
.addSourceLines(
"Foo.java",
"package com.example.thirdparty;",
"import com.example.jspecify.future.annotations.NullMarked;",
"import org.jspecify.nullness.NullMarked;",
"public class Foo {",
" @NullMarked",
" public static String foo(String s) {",
Expand All @@ -377,7 +377,7 @@ public void nullMarkedOuterMethodLevelWithLocalClass() {
.addSourceLines(
"Bar.java",
"package com.example.thirdparty;",
"import com.example.jspecify.future.annotations.NullMarked;",
"import org.jspecify.nullness.NullMarked;",
"public class Bar {",
" @NullMarked",
" public static Object bar() {",
Expand All @@ -401,7 +401,7 @@ public void nullMarkedOuterMethodLevelWithLocalClassInit() {
.addSourceLines(
"Test.java",
"package com.example.thirdparty;",
"import com.example.jspecify.future.annotations.NullMarked;",
"import org.jspecify.nullness.NullMarked;",
"public class Test {",
" @NullMarked",
" public static Object test() {",
Expand Down Expand Up @@ -570,7 +570,7 @@ public void nullUnmarkedPackageLevel() {
.addSourceLines(
"package-info.java",
"@NullUnmarked package com.uber.unmarked;",
"import com.example.jspecify.future.annotations.NullUnmarked;")
"import org.jspecify.nullness.NullUnmarked;")
.addSourceLines(
"MarkedBecauseAnnotatedFlag.java",
"package com.uber.marked;",
Expand Down Expand Up @@ -641,11 +641,11 @@ public void nullUnmarkedClassLevel() {
.addSourceLines(
"package-info.java",
"@NullMarked package com.example.thirdparty.marked;",
"import com.example.jspecify.future.annotations.NullMarked;")
"import org.jspecify.nullness.NullMarked;")
.addSourceLines(
"Foo.java",
"package com.uber.foo;",
"import com.example.jspecify.future.annotations.NullUnmarked;",
"import org.jspecify.nullness.NullUnmarked;",
"import org.jspecify.nullness.Nullable;",
"@NullUnmarked",
"public class Foo {",
Expand Down Expand Up @@ -700,7 +700,7 @@ public void nullUnmarkedClassLevelOuter() {
.addSourceLines(
"Bar.java",
"package com.uber.foo;",
"import com.example.jspecify.future.annotations.NullUnmarked;",
"import org.jspecify.nullness.NullUnmarked;",
"import org.jspecify.nullness.Nullable;",
"@NullUnmarked",
"public class Bar {",
Expand Down Expand Up @@ -742,7 +742,7 @@ public void nullUnmarkedMarkedClassLevelInner() {
.addSourceLines(
"Bar.java",
"package com.uber.foo;",
"import com.example.jspecify.future.annotations.NullUnmarked;",
"import org.jspecify.nullness.NullUnmarked;",
"import org.jspecify.nullness.Nullable;",
"public class Bar {",
" @NullUnmarked",
Expand Down Expand Up @@ -789,8 +789,8 @@ public void nullUnmarkedClassLevelDeep() {
.addSourceLines(
"Bar.java",
"package com.uber.foo;",
"import com.example.jspecify.future.annotations.NullMarked;",
"import com.example.jspecify.future.annotations.NullUnmarked;",
"import org.jspecify.nullness.NullMarked;",
"import org.jspecify.nullness.NullUnmarked;",
"import org.jspecify.nullness.Nullable;",
"public class Bar {",
" @NullUnmarked",
Expand Down Expand Up @@ -844,7 +844,7 @@ public void nullUnmarkedMethodLevel() {
.addSourceLines(
"Foo.java",
"package com.uber;",
"import com.example.jspecify.future.annotations.NullUnmarked;",
"import org.jspecify.nullness.NullUnmarked;",
"import org.jspecify.nullness.Nullable;",
"public class Foo {",
" @NullUnmarked",
Expand All @@ -871,8 +871,8 @@ public void nullUnmarkedOuterMethodLevelWithLocalClass() {
.addSourceLines(
"Bar.java",
"package com.example.thirdparty;",
"import com.example.jspecify.future.annotations.NullMarked;",
"import com.example.jspecify.future.annotations.NullUnmarked;",
"import org.jspecify.nullness.NullMarked;",
"import org.jspecify.nullness.NullUnmarked;",
"@NullMarked",
"public class Bar {",
" public static String takeNonNull(Object o) {",
Expand Down Expand Up @@ -953,8 +953,8 @@ public void nullUnmarkedAndAcknowledgeRestrictiveAnnotations() {
.addSourceLines(
"Foo.java",
"package com.uber;",
"import com.example.jspecify.future.annotations.NullMarked;",
"import com.example.jspecify.future.annotations.NullUnmarked;",
"import org.jspecify.nullness.NullMarked;",
"import org.jspecify.nullness.NullUnmarked;",
"import org.jspecify.nullness.Nullable;",
"@NullUnmarked",
"public class Foo {",
Expand Down Expand Up @@ -999,7 +999,7 @@ public void nullMarkedStaticImports() {
.addSourceLines(
"StaticMethods.java",
"package com.uber;",
"import com.example.jspecify.future.annotations.NullMarked;",
"import org.jspecify.nullness.NullMarked;",
"import org.jspecify.nullness.Nullable;",
"public final class StaticMethods {",
" private StaticMethods() {}",
Expand Down Expand Up @@ -1028,7 +1028,7 @@ public void nullMarkedStaticImports() {
"import static com.uber.StaticMethods.nullableCallee;",
"import static com.uber.StaticMethods.unmarkedCallee;",
"import static com.uber.StaticMethods.unmarkedNullableCallee;",
"import com.example.jspecify.future.annotations.NullMarked;",
"import org.jspecify.nullness.NullMarked;",
"import org.jspecify.nullness.Nullable;",
"@NullMarked",
"public class Test {",
Expand Down Expand Up @@ -1062,7 +1062,7 @@ public void dotClassSanityTest1() {
.addSourceLines(
"Test.java",
"package com.uber;",
"import com.example.jspecify.future.annotations.NullMarked;",
"import org.jspecify.nullness.NullMarked;",
"import org.jspecify.nullness.Nullable;",
"import java.lang.reflect.Field;",
"@NullMarked",
Expand Down Expand Up @@ -1104,7 +1104,7 @@ public void dotClassSanityTest2() {
.addSourceLines(
"Test.java",
"package com.uber;",
"import com.example.jspecify.future.annotations.NullMarked;",
"import org.jspecify.nullness.NullMarked;",
"import org.jspecify.nullness.Nullable;",
"import java.lang.reflect.Field;",
"@NullMarked",
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.example.jspecify.unannotatedpackage;

// Needed for annotating methods, should be removed and replaced with the standard
// JSpecify @NullMarked/@NullUnmarked annotations once v0.3.0 is out.
import com.example.jspecify.future.annotations.NullMarked;
import com.example.jspecify.future.annotations.NullUnmarked;
import org.jspecify.nullness.NullMarked;
import org.jspecify.nullness.NullUnmarked;

public class Methods {
@NullMarked
Expand Down

0 comments on commit 3da177a

Please sign in to comment.