报告未在 try-with-resources 语句中使用的 AutoCloseable 实例,也称为 Automatic Resource Management

这意味着还报告在 try-with-resources 可用前所使用的“在 try 前面/中打开,在 finally 中关闭”的样式。 在 Java 7 及更高版本中开发时,该检查意在取代所有已打开但未安全关闭的检查。

示例:


  private static void foo() throws IOException {
    InputStream profile = Thread.currentThread().getContextClassLoader().getResourceAsStream("/someFile");
    System.out.println(profile.read());
  }

使用以下选项配置检查: