JD.RC.EXPR.DEAD

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

Vulnerability and risk

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

Mitigation and prevention

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

Example 1

Copy
     void configure(final String path) throws IOException {
         BufferedReader in = new BufferedReader(new FileReader(path));
         if (in == null) {
             log("Was not able to access the file");
             return;
         }
 
         String line;
         while ((line = in.readLine()) != null) {
             parseConfiguration(line);
         }
     }

JD.RC.EXPR.DEAD is reported for the check on line 15: 'in' is not null due to the assignment on line 14.

Example 2

Copy
     void configure(final String path) throws IOException {
         BufferedReader in = null;
 
         try {
             in = new BufferedReader(new FileReader(path));
         } catch (FileNotFoundException e) {
             e.printStackTrace();
         }
 
         if (in == null) {
             log("Was not able to access the file");
             return;
         }
 
         String line;
         while ((line = in.readLine()) != null) {
             parseConfiguration(line);
         }
     }

JD.RC.EXPR.DEAD is not reported for the snippet: 'in' can be null on line 23 if FileNotFoundException is thrown by the FileReader constructor on line 18 .

Related checkers