Why this matters
Ensures safe handling of heterogeneous data.
Use instanceof/pattern matching and guard before casts; avoid ClassCastException.
Ensures safe handling of heterogeneous data.
Side-by-side examples engineers can pattern-match during review.
Map m = (Map) obj; String v = (String) m.get("v");if (obj instanceof Map<?,?> m) { Object v = m.get("v"); if (v instanceof String s) { /* use s */ } }(List<String>) objif (obj instanceof List<?> list) { /* ... */ }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.