`-XepAllSuggestionsAsWarnings` doesn't work for checks manually enabled with default severity
- Dominant language
- Java
- Stars
- 7.2k
- Forks
- 820
- Avg merge
- 5h 9m
- Merged PRs (30d)
- 50
Description
### Version
Error Prone 2.23.0
JDK 17
### Description
The `-XepAllSuggestionsAsWarnings` flag added by #3301 does not seem to work properly when you manually enable a check which is disabled by default, without overwriting its default severity.
When the default severity is 'suggestion', instead of being increased to 'warning' it remains at 'suggestion'.
I assume the underlying reason is:
- The severity is increased here
https://github.com/google/error-prone/blob/7acf133dc9fd0366afb57ee8e4582a78c808b73d/check_api/src/main/java/com/google/errorprone/scanner/ScannerSupplier.java#L172-L176
- But then here it is overwritten again with the default
https://github.com/google/error-prone/blob/7acf133dc9fd0366afb57ee8e4582a78c808b73d/check_api/src/main/java/com/google/errorprone/scanner/ScannerSupplier.java#L213-L215
Maybe that second code snippet could use `severities.putIfAbsent` instead (haven't test it yet though)?
### Reproduction steps
- Use `-XepAllSuggestionsAsWarnings`
- Use `-Xep:SwitchDefault` to enable that check, because it is disabled by default
(`SwitchDefault` has the default severity 'suggestion')
Bug: `SwitchDefault` is reported as 'suggestion' instead of 'warning'
### Workaround
When enabling the check also explicitly specify the severity, e.g. `-Xep:SwitchDefault:WARN`, but that has these disadvantages
- you might forget to do this (in case you don't apply `:WARN` for all checks), or it might be missing after a newer Error Prone version reduced the default severity of a check to 'suggestion'
- you might accidentally reduce the severity if you apply `:WARN` for all manually enabled checks, but some of them had 'error' as default severity
Contributor guide
Assessment
This issue has not been assessed yet.