Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@NotNull annotation on a local variable is ignored #756

Closed
mitasov-ra opened this issue Apr 6, 2023 · 2 comments
Closed

@NotNull annotation on a local variable is ignored #756

mitasov-ra opened this issue Apr 6, 2023 · 2 comments

Comments

@mitasov-ra
Copy link

mitasov-ra commented Apr 6, 2023

Consider the following example:

public class Main {
  public static void main(String[] args) {
    @NotNull String a = foo(); // line 3

    bar(a); // line 5

    System.out.println(a);
  }

  @Nullable
  private static String foo() {
    return null;
  }

  @Nullable
  private static String bar(@NotNull String bar) {
    return null;
  }
}

The expected behaviour for me is NullAway raising an error on line 3, but it raises on line 5.

And if I change method bar to accept @Nullable parameter, NullAway doesn't raise anything at all.

Meta

I'm using com.uber.nullaway:nullaway:0.10.10 with errorprone 3.0.1

Here's my Gradle configuration (inside compileJava):

import net.ltgt.gradle.errorprone.CheckSeverity

plugins {
    id 'java'
    id 'net.ltgt.errorprone' version '3.0.1'
}

dependencies {
    // ...

    // nullaway
    annotationProcessor 'com.uber.nullaway:nullaway:0.10.10'
    compileOnly 'com.uber.nullaway:nullaway-annotations:0.10.10'

    errorprone "com.google.errorprone:error_prone_core:2.18.0"

}

tasks.named('compileJava', JavaCompile) {
    options.encoding 'UTF-8'
    options.errorprone {
        disableWarningsInGeneratedCode.set(true)
        // invalid null check raise error log
        check("NullAway", CheckSeverity.ERROR)
        // base-package for analyse annotated classes
        option("NullAway:AnnotatedPackages", "my.package") // ! line changed due to NDA
        // exclude generated classes with @Generated
        option("NullAway:TreatGeneratedAsUnannotated", true)
        // exclude classes with given annotation
        option("NullAway:ExcludedClassAnnotations", "lombok.Builder")
        // take assertions into consideration
        option("NullAway:AssertsEnabled", true)
        // exclude unit-tests from checking
        option("ExcludedPaths", ".*/src/test/(java|kotlin)/.*")
        // annotation is taken not from super class
        option("NullAway:ExhaustiveOverride", true)
        // libs are scanned and defaults for unannotated
        // methods is @NotNull Object method(@Nullable param)
        option("NullAway:AcknowledgeRestrictiveAnnotations", true)
        disable(
            "ImmutableEnumChecker",
        )
    }
}
@mitasov-ra
Copy link
Author

Sorry, just figured out this is duplicate of #561

@msridhar
Copy link
Collaborator

msridhar commented Sep 2, 2023

Duplicate of #561

@msridhar msridhar marked this as a duplicate of #561 Sep 2, 2023
@msridhar msridhar closed this as completed Sep 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants