Why this matters
Unsafe casting can lead to runtime ClassCastException errors. Always use instanceof checks before performing type casting.
Ensure that instanceof checks are used before performing explicit type casting to prevent ClassCastException.
Unsafe casting can lead to runtime ClassCastException errors. Always use instanceof checks before performing type casting.
Side-by-side examples engineers can pattern-match during review.
private String hexString(Object o) {
return Integer.toHexString((Integer) o); // Noncompliant if hexString is called with a String for example
}private String hexString(Integer i) {
return Integer.toHexString(i);
}From the same buckets as this rule.
Check if loops use equality operators (== or !=) in termination conditions. These can lead to infinite loops if the condition is never met exactly. Instead, use relational operators like < or > for safer loop termination.