Varifier false positive when the functional interface is inferred by the generic type
- Dominant language
- Java
- Stars
- 7.2k
- Forks
- 820
- Avg merge
- 5h 9m
- Merged PRs (30d)
- 50
Description
```console
AbstractTraceReader.java:72: warning: [Varifier] Consider using > `var` here to avoid boilerplate.
List> 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.
```java
List> 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.
```java
var extractors = List.>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.
```console
warning: [Varifier] Consider using `var` here to avoid boilerplate.
LoadingCache cache = Caffeine.newBuilder().build(k -> -k);
```
Contributor guide
Assessment
This issue has not been assessed yet.