File: SuppressWarningsWithoutExplanation.md

package info (click to toggle)
error-prone-java 2.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 15,076 kB
  • sloc: java: 171,398; xml: 1,459; sh: 34; makefile: 7
file content (20 lines) | stat: -rw-r--r-- 670 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Suppressions for `unchecked` or `rawtypes` warnings should have an accompanying
comment to explain why the javac warning is safe to ignore.

Rather than just suppressing the warning:

```java
@SuppressWarnings("unchecked")
public ImmutableList<Object> performScaryCast(ImmutableList<String> strings) {
  return (ImmutableList<Object>) (ImmutableList<?>) strings;
}
```

Provide a concise explanation for why it is safe:

```java
@SuppressWarnings("unchecked") // Safe covariant cast, given ImmutableList cannot be added to.
public ImmutableList<Object> performScaryCast(ImmutableList<String> strings) {
  return (ImmutableList<Object>) (ImmutableList<?>) strings;
}
```