A static-analysis warning is a diagnostic that is irrelevant, excessive, or otherwise unhelpful in a particular context. Static analyzers can prevent common mistakes, but their findings require judgment rather than automatic acceptance. section 1.3.4 section 1.8
Intentional unused collection
An analyzer may report that debugData is written but never read. If the collection exists deliberately for debugging or memory-dump analysis, suppress the warning locally and document the reason. section 1.3.4
Reduce unwanted warnings without hiding useful diagnostics:
- Configure an inspection or disable it selectively for a project or specific code area. section 1.3.4
- Prefer a suppression over disabling an entire inspection when the exception is narrow and intentional. section 1.3.4
- Apply suppressions to the narrowest possible scope; broad method-level annotations can hide later, more useful warnings. section 1.3.4
- Rearrange code to make its intent easier for the analyzer to understand, and use code reviews, dynamic analysis, and tests alongside static analysis. section 1.8
//Collection is never read: intended (used for debug) //noinspection MismatchedQueryAndUpdateOfCollection List<String> debugData = new ArrayList<>();
Shows a narrow IntelliJ IDEA suppression for an intentionally unread collection. section 1.3.4
Table 1.1 Suppression of bad shift amount in different static analyzers
|
Static analyzer
|
Suppression annotation
|
|---|---|
|
IntelliJ IDEA
|
@SuppressWarnings("ShiftOutOfRange")
|
|
Error Prone
|
@SuppressWarnings("BadShiftAmount")
|
|
SonarLint
|
@SuppressWarnings("squid:S2183")
|
|
SpotBugs
|
@SuppressFBWarnings("ICAST_BAD_SHIFT_AMOUNT")
|
Compares suppression identifiers across IntelliJ IDEA, Error Prone, SonarLint, and SpotBugs. section 1.3.4
