Skip to content

Files

Latest commit

 

History

History
24 lines (15 loc) · 790 Bytes

UnnecessaryInstanceOfCheck.md

File metadata and controls

24 lines (15 loc) · 790 Bytes

Pattern: Unnecessary instanceof check

Issue: -

Description

This rule finds instanceof checks that cannot possibly evaluate to true. For instance, checking that (!variable instanceof String) will never be true because the result of a not expression is always a boolean.

Example of violations:

if (!variable instanceof String) { ... }    // always false
def x = !variable instanceof String         // always false

if (!variable instanceof Boolean) { ... }    // always true
def x = !variable instanceof Boolean         // always true

// this code is OK
if (!(variable instanceof String)) { ... }

Further Reading