From 296d583fa449e3866cc5307d90db6fe48c0a0153 Mon Sep 17 00:00:00 2001 From: Lazaro Clapp Date: Wed, 4 Jan 2023 14:32:49 -0500 Subject: [PATCH] Have :nullaway depend on :annotations --- .../{ => annotations}/Initializer.java | 25 +++++++++++-------- nullaway/build.gradle | 4 +-- .../nullaway/handlers/MethodNameUtil.java | 2 +- .../testdata/CheckFieldInitNegativeCases.java | 2 +- .../testdata/CheckFieldInitPositiveCases.java | 2 +- .../testdata/ReadBeforeInitNegativeCases.java | 2 +- .../testdata/ReadBeforeInitPositiveCases.java | 2 +- 7 files changed, 21 insertions(+), 18 deletions(-) rename annotations/src/main/java/com/uber/nullaway/{ => annotations}/Initializer.java (53%) diff --git a/annotations/src/main/java/com/uber/nullaway/Initializer.java b/annotations/src/main/java/com/uber/nullaway/annotations/Initializer.java similarity index 53% rename from annotations/src/main/java/com/uber/nullaway/Initializer.java rename to annotations/src/main/java/com/uber/nullaway/annotations/Initializer.java index a489ab4fc8..e5988d3106 100644 --- a/annotations/src/main/java/com/uber/nullaway/Initializer.java +++ b/annotations/src/main/java/com/uber/nullaway/annotations/Initializer.java @@ -20,7 +20,7 @@ * THE SOFTWARE. */ -package com.uber.nullaway; +package com.uber.nullaway.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -30,16 +30,19 @@ /** * An annotation used to mark a method as an initializer. * - *

During initialization checking (see {@link - * https://github.com/uber/NullAway/wiki/Error-Messages#initializer-method-does-not-guarantee-nonnull-field-is-initialized--nonnull-field--not-initialized}), - * NullAway considers a method marked with any annotation with simple name {@code @Initializer} to - * denote an initializer method. Initializer methods are assumed by NullAway to always be called - * before any other method of the class that is not a constructor or called from a constructor. This - * means a non-null field is considered to be properly initialized if it's set by such an - * initializer method. By design, NullAway doesn't check for such initialization, since an important - * use case of initializer methods is documenting methods used by annotation processors or external - * frameworks as part of object set up (e.g. {@code android.app.Activity.onCreate} or {@code - * javax.annotation.processing.Processor.init}). + *

During initialization checking (see {@see NullAway + * Wiki}), NullAway considers a method marked with any annotation with simple name + * {@code @Initializer} to denote an initializer method. Initializer methods are assumed by NullAway + * to always be called before any other method of the class that is not a constructor or called from + * a constructor. This means a non-null field is considered to be properly initialized if it's set + * by such an initializer method. By design, NullAway doesn't check for such initialization, since + * an important use case of initializer methods is documenting methods used by annotation processors + * or external frameworks as part of object set up (e.g. {@code android.app.Activity.onCreate} or + * {@code javax.annotation.processing.Processor.init}). Note that there are other ways of defining + * initializer methods from external libraries (i.e. library models), and that a method overriding + * an initializer method is always considered an initializer method (again, for the sake of + * framework events such as {@code onCreate}). */ @Retention(RetentionPolicy.CLASS) @Target({ElementType.METHOD}) diff --git a/nullaway/build.gradle b/nullaway/build.gradle index 2c0f04a79f..d6c4463dca 100644 --- a/nullaway/build.gradle +++ b/nullaway/build.gradle @@ -25,11 +25,11 @@ configurations { } dependencies { + compileOnly project(":annotations") compileOnly deps.apt.autoValueAnnot annotationProcessor deps.apt.autoValue compileOnly deps.apt.autoServiceAnnot annotationProcessor deps.apt.autoService - compileOnly deps.test.inferAnnotations compileOnly deps.build.jsr305Annotations compileOnly deps.test.jetbrainsAnnotations @@ -38,6 +38,7 @@ dependencies { implementation deps.build.checkerDataflow implementation deps.build.guava + testImplementation project(":annotations") testImplementation deps.test.junit4 testImplementation(deps.build.errorProneTestHelpers) { exclude group: "junit", module: "junit" @@ -48,7 +49,6 @@ dependencies { testImplementation deps.test.cfCompatQual testImplementation deps.build.jspecify testImplementation project(":test-java-lib") - testImplementation deps.test.inferAnnotations testImplementation deps.apt.jakartaInject testImplementation deps.apt.javaxInject testImplementation deps.test.rxjava2 diff --git a/nullaway/src/main/java/com/uber/nullaway/handlers/MethodNameUtil.java b/nullaway/src/main/java/com/uber/nullaway/handlers/MethodNameUtil.java index f1c2804a11..849e8a9957 100644 --- a/nullaway/src/main/java/com/uber/nullaway/handlers/MethodNameUtil.java +++ b/nullaway/src/main/java/com/uber/nullaway/handlers/MethodNameUtil.java @@ -22,10 +22,10 @@ * THE SOFTWARE. */ -import com.facebook.infer.annotation.Initializer; import com.google.errorprone.util.ASTHelpers; import com.sun.tools.javac.code.Symbol; import com.sun.tools.javac.util.Name; +import com.uber.nullaway.annotations.Initializer; import org.checkerframework.nullaway.dataflow.cfg.node.MethodInvocationNode; import org.checkerframework.nullaway.dataflow.cfg.node.Node; diff --git a/nullaway/src/test/resources/com/uber/nullaway/testdata/CheckFieldInitNegativeCases.java b/nullaway/src/test/resources/com/uber/nullaway/testdata/CheckFieldInitNegativeCases.java index 7b4df6ab36..9ef64f8f70 100644 --- a/nullaway/src/test/resources/com/uber/nullaway/testdata/CheckFieldInitNegativeCases.java +++ b/nullaway/src/test/resources/com/uber/nullaway/testdata/CheckFieldInitNegativeCases.java @@ -22,8 +22,8 @@ package com.uber.nullaway.testdata; -import com.facebook.infer.annotation.Initializer; import com.google.errorprone.annotations.concurrent.LazyInit; +import com.uber.nullaway.annotations.Initializer; import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.junit.Before; import org.junit.BeforeClass; diff --git a/nullaway/src/test/resources/com/uber/nullaway/testdata/CheckFieldInitPositiveCases.java b/nullaway/src/test/resources/com/uber/nullaway/testdata/CheckFieldInitPositiveCases.java index 15ba2ef099..db632ade1c 100755 --- a/nullaway/src/test/resources/com/uber/nullaway/testdata/CheckFieldInitPositiveCases.java +++ b/nullaway/src/test/resources/com/uber/nullaway/testdata/CheckFieldInitPositiveCases.java @@ -22,7 +22,7 @@ package com.uber.nullaway.testdata; -import com.facebook.infer.annotation.Initializer; +import com.uber.nullaway.annotations.Initializer; import javax.annotation.Nullable; /** Created by msridhar on 3/7/17. */ diff --git a/nullaway/src/test/resources/com/uber/nullaway/testdata/ReadBeforeInitNegativeCases.java b/nullaway/src/test/resources/com/uber/nullaway/testdata/ReadBeforeInitNegativeCases.java index f00c95eb94..c12fe4ca05 100644 --- a/nullaway/src/test/resources/com/uber/nullaway/testdata/ReadBeforeInitNegativeCases.java +++ b/nullaway/src/test/resources/com/uber/nullaway/testdata/ReadBeforeInitNegativeCases.java @@ -24,7 +24,7 @@ import static com.uber.nullaway.testdata.Util.castToNonNull; -import com.facebook.infer.annotation.Initializer; +import com.uber.nullaway.annotations.Initializer; import javax.annotation.Nullable; public class ReadBeforeInitNegativeCases { diff --git a/nullaway/src/test/resources/com/uber/nullaway/testdata/ReadBeforeInitPositiveCases.java b/nullaway/src/test/resources/com/uber/nullaway/testdata/ReadBeforeInitPositiveCases.java index 44873c8d97..2858babc93 100644 --- a/nullaway/src/test/resources/com/uber/nullaway/testdata/ReadBeforeInitPositiveCases.java +++ b/nullaway/src/test/resources/com/uber/nullaway/testdata/ReadBeforeInitPositiveCases.java @@ -22,7 +22,7 @@ package com.uber.nullaway.testdata; -import com.facebook.infer.annotation.Initializer; +import com.uber.nullaway.annotations.Initializer; public class ReadBeforeInitPositiveCases {