Syntactically invalid `@Var` patch suggestion
- Dominant language
- Java
- Stars
- 7.2k
- Forks
- 820
- Avg merge
- 5h 9m
- Merged PRs (30d)
- 50
Description
Consider the following (admittedly bad) code:
```java
import java.util.function.Consumer;
class Example {
Consumer heatTheRoom() {
return v -> {
while (v < Integer.MAX_VALUE) {
v++;
}
};
}
}
```
Compile the code as follows:
```sh
javac \
-XDcompilePolicy=simple \
-processorpath error_prone_core-2.3.3-with-dependencies.jar \
'-Xplugin:ErrorProne -XepDisableAllChecks -Xep:Var:WARN' \
Example.java
```
This yields the following warning:
```
Example.java:5: warning: [Var] Non-constant variable missing @Var annotation
return v -> {
^
(see https://errorprone.info/bugpattern/Var)
Did you mean 'return @Var v -> {'?
1 warning
```
If this suggestion were accepted using `-XepPatchChecks:Var` the resulting code would be syntactically invalid because because parentheses and a variable type declaration are missing. I.e., it should be `return (@Var Integer v) -> {` rather than `return @Var v -> {`.
Contributor guide
Assessment
This issue has not been assessed yet.