Следующий код заставляет Eclipse отображать предупреждение о мертвом коде, хотя код доступен.Я что-то здесь упускаю, или это ошибка Eclipse / javac?
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
}
}
}
}
Код печатает List is null
Я использую Eclipse 4.7.3a (Oxygen.3a) иJDK 8_162