Eclipse为可访问的代码提供了死代码警告

时间:2018-05-15 13:46:18

标签: java eclipse javac

以下代码导致Eclipse显示死代码警告,尽管代码可以访问。我在这里遗漏了什么,或者这是一个Eclipse / javac错误?

//bind to $name
if ($stmt = $conn->prepare("SELECT Industry FROM industries")) {
    $stmt->bind_result($name);
    $OK = $stmt->execute();
}
//put all of the resulting names into a PHP array
$result_array = Array();
while($stmt->fetch()) {
    $result_array[] = $name;
}
//convert the PHP array into JSON format, so it works with javascript
$json_array = json_encode($result_array);

代码打印import java.util.ArrayList; public class DeadCodeDemo { public static class SomeClosable implements AutoCloseable { @Override public void close() throws Exception { } } public static ArrayList<String> throwRuntime() { throw new RuntimeException(); } public static void main(String[] args) { ArrayList<String> list = null; try { try (SomeClosable c = new SomeClosable()) { list = throwRuntime(); } try (SomeClosable c = new SomeClosable()) { list.clear(); } } catch (Exception e) { if (list != null) { // Warning: Redundant null check: The variable list cannot be null at this location System.out.println("List is not null"); } else { System.out.println("List is null"); // Warning: Dead code } } } }

我使用Eclipse 4.7.3a(Oxygen.3a)和JDK 8_162

1 个答案:

答案 0 :(得分:4)

认为它是this issue,仍处于打开状态。

请记住,这是Eclipse warning,而不是javac - 在问题得到解决之前,这几乎是你应该关心的事情(即使现在已经7岁了)