Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Edited by sciSpider Java v3.0

...

Code Block
bgColor#FFCCCC
@SuppressWarnings("unchecked""unchecked") class Legacy {
  Set s = new HashSet();
  public final void doLogic(int a,char c) {
    s.add(a);
    s.add(c); // Type unsafe operation, ignored
  }
}

...

Code Block
bgColor#ccccff
class Legacy {
  @SuppressWarnings("unchecked""unchecked")  Set s = new HashSet();
  public final void doLogic(int a,char c) {
    s.add(a); // Produces unchecked warning
    s.add(c); // Produces unchecked warning
  }
}

...

Code Block
bgColor#FFCCCC
@SuppressWarnings("unchecked""unchecked")
public <T>&lt;T&gt; T[] toArray(T[] a) {
  if (a.length <&lt; size)
    return (T[]) Arrays.copyOf(elements, size, a.getClass()); // Produces unchecked warning
 // ...
}

...

Code Block
bgColor#ccccff
// ...
@SuppressWarnings("unchecked"&quot;unchecked&quot;) T[] result =
(T[]) Arrays.copyOf(elements, size, a.getClass());
return result;
// ...

...

Search for vulnerabilities resulting from the violation of this rule on the CERT website.

References

[Bloch 08] Item 24: "Eliminate unchecked warnings"

...

SCP03-J. Do not reuse names      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;05. Scope (SCP)      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;06. Integers (INT)