【发布时间】:2019-05-24 09:25:00
【问题描述】:
强化安全运行不合规代码
public static A read(String path) throws IOException, ClassNotFoundException {
try (ObjectInputStream os = new ObjectInputStream(new GZIPInputStream(new FileInputStream(path)))) {
return (A) os.readObject();
}
}
上面写着 "Unreleased Resource: Streams" ,但它在 try-with-resource 里面,那么可能是什么问题?请帮帮我。
【问题讨论】:
-
仅供参考:如果您返回在“try-with-resources”中声明的资源,它将在返回时关闭。这意味着如果您返回资源,它将为空。不相信我?试试看。
标签: java file-io fortify objectinputstream