Skip to content

Commit

Permalink
Revert "Update to JSpecify 0.3.0-alpha-1 (uber#673)"
Browse files Browse the repository at this point in the history
This reverts commit 3da177a.
  • Loading branch information
msridhar committed Jul 18, 2023
1 parent 3a08a9c commit ba96f9e
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 40 deletions.
20 changes: 8 additions & 12 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,12 +77,8 @@ subprojects { project ->
check("SymbolToString", CheckSeverity.ERROR)
}
} else {
// 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
// disable Error Prone checking of our code on JDK 8, as more recent versions don't run on JDK 8
options.errorprone.enabled = false
}
}

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.3.0-alpha-1",
jspecify : "org.jspecify:jspecify:0.2.0",
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 org.jspecify.nullness.NullMarked;",
"import com.example.jspecify.future.annotations.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 org.jspecify.nullness.NullMarked;",
"import com.example.jspecify.future.annotations.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 org.jspecify.nullness.NullMarked;",
"import com.example.jspecify.future.annotations.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 org.jspecify.nullness.NullMarked;",
"import com.example.jspecify.future.annotations.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 org.jspecify.nullness.NullMarked;",
"import com.example.jspecify.future.annotations.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 org.jspecify.nullness.NullMarked;",
"import com.example.jspecify.future.annotations.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 org.jspecify.nullness.NullMarked;",
"import com.example.jspecify.future.annotations.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 org.jspecify.nullness.NullMarked;",
"import com.example.jspecify.future.annotations.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 org.jspecify.nullness.NullMarked;",
"import com.example.jspecify.future.annotations.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 org.jspecify.nullness.NullUnmarked;")
"import com.example.jspecify.future.annotations.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 org.jspecify.nullness.NullMarked;")
"import com.example.jspecify.future.annotations.NullMarked;")
.addSourceLines(
"Foo.java",
"package com.uber.foo;",
"import org.jspecify.nullness.NullUnmarked;",
"import com.example.jspecify.future.annotations.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 org.jspecify.nullness.NullUnmarked;",
"import com.example.jspecify.future.annotations.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 org.jspecify.nullness.NullUnmarked;",
"import com.example.jspecify.future.annotations.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 org.jspecify.nullness.NullMarked;",
"import org.jspecify.nullness.NullUnmarked;",
"import com.example.jspecify.future.annotations.NullMarked;",
"import com.example.jspecify.future.annotations.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 org.jspecify.nullness.NullUnmarked;",
"import com.example.jspecify.future.annotations.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 org.jspecify.nullness.NullMarked;",
"import org.jspecify.nullness.NullUnmarked;",
"import com.example.jspecify.future.annotations.NullMarked;",
"import com.example.jspecify.future.annotations.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 org.jspecify.nullness.NullMarked;",
"import org.jspecify.nullness.NullUnmarked;",
"import com.example.jspecify.future.annotations.NullMarked;",
"import com.example.jspecify.future.annotations.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 org.jspecify.nullness.NullMarked;",
"import com.example.jspecify.future.annotations.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 org.jspecify.nullness.NullMarked;",
"import com.example.jspecify.future.annotations.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 org.jspecify.nullness.NullMarked;",
"import com.example.jspecify.future.annotations.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 org.jspecify.nullness.NullMarked;",
"import com.example.jspecify.future.annotations.NullMarked;",
"import org.jspecify.nullness.Nullable;",
"import java.lang.reflect.Field;",
"@NullMarked",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2018-2022 The JSpecify Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.jspecify.future.annotations;

// Note: Copied from
// https://github.com/jspecify/jspecify/blob/main/src/main/java/org/jspecify/nullness/NullMarked.java
// used for testing JSpecify features (such as @NullMarked on methods), which aren't part of
// JSpecify v0.2.0.
// This annotation should be deleted and its references replaced with
// org.jspecify.nullness.NullMarked once JSpecify v0.3.0 is out.
// This test resource is not redistributed with NullAway.

import static java.lang.annotation.ElementType.CONSTRUCTOR;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PACKAGE;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

/**
* Indicates that the annotated element and the code transitively <a
* href="https://docs.oracle.com/en/java/javase/18/docs/api/java.compiler/javax/lang/model/element/Element.html#getEnclosedElements()">enclosed</a>
* within it is <b>null-marked code</b>: type usages are generally considered to exclude {@code
* null} as a value unless specified otherwise (special cases to be covered below). Using this
* annotation avoids the need to write {@link NonNull @NonNull} many times throughout your code.
*
* <p><b>WARNING:</b> This annotation is under development, and <i>any</i> aspect of its naming,
* location, or design may change before 1.0. <b>Do not release libraries using this annotation at
* this time.</b>
*/
@Documented
@Target({TYPE, METHOD, CONSTRUCTOR, PACKAGE})
@Retention(RUNTIME)
public @interface NullMarked {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright 2022 The JSpecify Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.jspecify.future.annotations;

// Note: Copied from
// https://github.com/jspecify/jspecify/blob/main/src/main/java/org/jspecify/nullness/NullUnmarked.java
// as it isn't part of JSpecify v0.2.0.
// This annotation should be deleted and its references replaced with
// org.jspecify.nullness.NullUnmarked once JSpecify v0.3.0 is out.
// This test resource is not redistributed with NullAway.

import static java.lang.annotation.ElementType.CONSTRUCTOR;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PACKAGE;
import static java.lang.annotation.ElementType.TYPE;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Indicates that the annotated element and the code transitively {@linkplain
* javax.lang.model.element.Element#getEnclosedElements() enclosed} within it is <b>null-unmarked
* code</b>: there, type usages generally have <b>unspecified nullness</b> unless explicitly
* annotated otherwise.
*
* <p>This annotation's purpose is to ease migration of a large existing codebase to null-marked
* status. It makes it possible to "flip the default" for new code added to a class or package even
* before that class or package has been fully migrated. Since new code is the most important code
* to analyze, this is strongly recommended as a temporary measure whenever necessary. However, once
* a codebase has been fully migrated it would be appropriate to ban use of this annotation.
*
* <p>For a guided introduction to JSpecify nullness annotations, please see the <a
* href="http://jspecify.org/docs/user-guide">User Guide</a>.
*
* <p><b>Warning:</b> These annotations are under development, and <b>any</b> aspect of their
* naming, locations, or design is subject to change until the JSpecify 1.0 release. Moreover,
* supporting analysis tools will track with these changes on varying schedules. Releasing a library
* using these annotations in its API is <b>strongly discouraged</b> at this time.
*
* <h2>Null-marked and null-unmarked code</h2>
*
* <p>{@link NullMarked} and this annotation work as a pair to include and exclude sections of code
* from null-marked status.
*
* <p>Code is considered null-marked if the most narrowly enclosing element annotated with either of
* these two annotations is annotated with {@code @NullMarked}.
*
* <p>Otherwise it is considered null-unmarked. This can happen in two ways: either it is more
* narrowly enclosed by a {@code @NullUnmarked}-annotated element than by any
* {@code @NullMarked}-annotated element, or neither annotation is present on any enclosing element.
* No distinction is made between these cases.
*
* <h2>Unspecified nullness</h2>
*
* <p>An unannotated type usage in null-unmarked code has <b>unspecified nullness</b>. There is
* <i>some</i> correct way to annotate it, but that information is missing; the usage conveys <b>no
* information</b> about whether it includes or excludes {@code null} as a value. Only type usages
* within null-unmarked code may have unspecified nullness. (<a
* href="https://bit.ly/3ppb8ZC">Why?</a>)
*
* <p>Unspecified nullness is (will be) explained comprehensively in the <a
* href="http://jspecify.org/docs/user-guide">User Guide</a>.
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({TYPE, METHOD, CONSTRUCTOR, PACKAGE})
public @interface NullUnmarked {}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.example.jspecify.unannotatedpackage;

import org.jspecify.nullness.NullMarked;
import org.jspecify.nullness.NullUnmarked;
// 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;

public class Methods {
@NullMarked
Expand Down

0 comments on commit ba96f9e

Please sign in to comment.