Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

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

13     void configure(final String path) throws IOException {
14         BufferedReader in = new BufferedReader(new FileReader(path));
15         if (in == null) {
16             log("Was not able to access the file");
17             return;
18         }
19 
20         String line;
21         while ((line = in.readLine()) != null) {
22             parseConfiguration(line);
23         }
24     }

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

14     void configure(final String path) throws IOException {
15         BufferedReader in = null;
16 
17         try {
18             in = new BufferedReader(new FileReader(path));
19         } catch (FileNotFoundException e) {
20             e.printStackTrace();
21         }
22 
23         if (in == null) {
24             log("Was not able to access the file");
25             return;
26         }
27 
28         String line;
29         while ((line = in.readLine()) != null) {
30             parseConfiguration(line);
31         }
32     }

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