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

Varifier false positive when the declared type is annotated #4698

Open
ben-manes opened this issue Nov 23, 2024 · 0 comments
Open

Varifier false positive when the declared type is annotated #4698

ben-manes opened this issue Nov 23, 2024 · 0 comments

Comments

@ben-manes
Copy link

ben-manes commented Nov 23, 2024

When enabling NullAway's jspecify mode, the use of arrays needs to be annotated for stricter nullability. For example,

.../LocalAsyncCache.java:818: warning: [NullAway] Writing @Nullable expression into array with @NonNull contents.
          oldValue[0] = Async.getIfReady(oldValueFuture);

To satisfy this check without a suppression requires the change

-var oldValue = (V[]) new Object[1];
+@Nullable V[] oldValue = (V[]) new Object[1];

ErrorProne then emits a warning,

.../LocalAsyncCache.java:800: warning: [Varifier] Consider using `var` here to avoid boilerplate.
      @Nullable V[] oldValue = (V[]) new Object[1];
                    ^
    (see https://errorprone.info/bugpattern/Varifier)
  Did you mean '@Nullable var oldValue = (V[]) new Object[1];'?

However that suggestion is invalid by JLS and instead the warning must be suppressed.

.../LocalAsyncCache.java:800: error: annotation interface not applicable to this kind of declaration
        @Nullable var oldValue = (V[]) new Object[1];
        ^
  1 error

Note that the annotation is not carried forward in the inferred type for NullAway to use if instead trying to resolve both checks

var oldValue = (@Nullable V[]) new Object[1];
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

1 participant