Skip to content

Commit

Permalink
Have :nullaway depend on :annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
lazaroclapp committed Jan 4, 2023
1 parent 8aa428f commit 296d583
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,16 +30,19 @@
/**
* An annotation used to mark a method as an initializer.
*
* <p>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}).
* <p>During initialization checking (see {@see <a
* href=https://github.com/uber/NullAway/wiki/Error-Messages#initializer-method-does-not-guarantee-nonnull-field-is-initialized--nonnull-field--not-initialized>NullAway
* Wiki</a>}), 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})
Expand Down
4 changes: 2 additions & 2 deletions nullaway/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

package com.uber.nullaway.testdata;

import com.facebook.infer.annotation.Initializer;
import com.uber.nullaway.annotations.Initializer;

public class ReadBeforeInitPositiveCases {

Expand Down

0 comments on commit 296d583

Please sign in to comment.