google / google/error-prone

[Feature request] Automatically disable checks based on target Java version

Open
#4,208 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
7.2k
Forks
820
Avg merge
5h 9m
Merged PRs (30d)
50

Description

Some checks are only relevant for a certain Java version:

| Check | Minimum Java version |
| - | - |
| `JavaUtilDate` | 8 (unless Joda-Time is considered a good solution as well) |
| `PreferJavaTimeOverload` ? | 8 |
| `UnnecessaryAnonymousClass` | 8 |
| `UnnecessaryFinal` | 8 |
| `TryWithResourcesVariable` | 9 |
| `Varifier` | 10 |
| `StatementSwitchToExpressionSwitch` | 14 (check already considers this) |

Would it be possible that Error Prone could automatically disable such checks based on the target Java version (`-source` & `-target` / `--release`) used during compilation?

There would be the following advantages with this:
- For a Maven project where the `main` code has a lower target version than the `test` code, that would allow to enable checks which are (for now) only relevant for test code, without needing two separate compiler configurations for main and test code
- You could enable checks which you would like to enforce in the future once you increase the target version of your code; if you only add those checks with `:OFF` for now, then it is likely that you forget to enable them again
- It might allow enabling by default some Error Prone checks which are currently disabled by default (possibly because they are only relevant for a certain Java version)

As side note: The Error Prone checks mentioned above are currently all disabled by default and have to be enabled manually. But as mentioned in the list above, even in that case it would be useful if they would be ignored based on the Java target version (or at least there could be an opt-in Error Prone flag which makes it behave that way).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.