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 functional interface is inferred by the generic type #4578

Open
ben-manes opened this issue Sep 15, 2024 · 0 comments

Comments

@ben-manes
Copy link

ben-manes commented Sep 15, 2024

AbstractTraceReader.java:72: warning: [Varifier] Consider using > `var` here to avoid boilerplate.
 
       List<UnaryOperator<InputStream>> extractors = List.of(
                                        ^
     (see https://errorprone.info/bugpattern/Varifier)
   Did you mean 'var extractors = List.of('?

This suggestion is not feasible because inferring to the functional interface must be done explicitly.

List<UnaryOperator<InputStream>> extractors = List.of(
    in -> tryXz(in), in -> tryCompressed(in), this::tryArchived);

To satisfy this check requires using a type witness. If that was intended then the suggestion should rewrite it correctly, e.g.

var extractors = List.<UnaryOperator<InputStream>>of(
    in -> tryXz(in), in -> tryCompressed(in), this::tryArchived);

Another related case is the inference from the cache builder, where the generic type has to be added to the lambda parameter to comply with this suggestion.

warning: [Varifier] Consider using `var` here to avoid boilerplate.
    LoadingCache<Integer, Integer> cache = Caffeine.newBuilder().build(k -> -k);
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