为什么 Lombok @Cleanup 使用 [Collections.singletonList().get(0)]?

Why Lombok @Cleanup use [Collections.singletonList().get(0)]?

我不明白为什么lombok使用singletonList,这里是一个演示:

@Cleanup FileInputStream fos = new FileInputStream("aa.txt");

构建后:

FileInputStream fos = new FileInputStream("aa.txt");
try {
   fos.read();
} finally {
   //I think [fos != null] should be better
   if (Collections.singletonList(fos).get(0) != null) {
       fos.close();
   }
}

此处为 Lombok 项目开发人员。

我们正在解决会发出无用空检查警告的 linter 工具。对于正常生成的方法,我们只是用 @SuppressWarnings 标记该方法,您的 linter 工具可能需要意识到它不应该抱怨它的任何其他注释,但不能用 @Cleanup 来完成。