JD.RC.EXPR.DEAD

JD.RC.EXPR.DEAD は、ローカル変数のチェックが行われると起動されます。ただし、そのチェックの結果は常に 'false' の値になります。したがって、この状況においてはコードのブロックは実行されません。

脆弱性とリスク

ロジックに欠陥があります。チェックは、コンパイル時に未知のプロパティに対してのみ実行されます。

軽減と防止

正しい変数と正しい値に対してチェックを行っていることを確認してください。

例 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 が、15 行目のチェックに対して報告されています。'in' は 14 行目の代入による NULL ではありません。

例 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 はスニペットに対して報告されていません。18 行目で FileNotFoundException が FileReader コンストラクタによってスローされた場合、23 行目の 'in' は NULL である可能性があります。

関連チェッカー