JD.RC.EXPR.CHECK

JD.RC.EXPR.CHECK is triggered when a local variable is checked even though that check will always result in a 'true' value, so the block of code will always execute under this condition.

Vulnerability and risk

Logic flaw. Checks should only be done for properties that are not known in compile time.

Mitigation and prevention

Make sure that you are checking the right variables for the right values.

Example 1

Copy
     void handleEvent(AWTEvent event) {
         if (event instanceof MouseEvent) {
             if (event != null) {
                 handleMouseEvent((MouseEvent) event);
             }
         }
     }

JD.RC.EXPR.CHECK is reported for the check on line 15, since the check on line 14 guarantees that 'event' is not null;

Example 2

Copy
     void handleEvent(AWTEvent event) {
         if (event != null) {
             if (event instanceof MouseEvent) {
                 handleMouseEvent((MouseEvent) event);
             }
         }
     }

JD.RC.EXPR.CHECK is not reported for the snippet: the null check on line 14 does not guarantee that the 'event' is an instance of the MouseEvent class.

Related checkers