diff --git a/infer/tests/codetoanalyze/java/infer/ResourceLeaks.java b/infer/tests/codetoanalyze/java/infer/ResourceLeaks.java index 576038085..50ca6fed7 100644 --- a/infer/tests/codetoanalyze/java/infer/ResourceLeaks.java +++ b/infer/tests/codetoanalyze/java/infer/ResourceLeaks.java @@ -101,16 +101,18 @@ public class ResourceLeaks { } public static void twoResourcesHeliosFix() throws IOException { - FileInputStream fis = new FileInputStream(new File("whatever.txt")); + FileInputStream fis = null; + FileOutputStream fos = null; try { - FileOutputStream fos = new FileOutputStream(new File("everwhat.txt")); + fis = new FileInputStream(new File("whatever.txt")); try { + fos = new FileOutputStream(new File("everwhat.txt")); fos.write(fis.read()); } finally { - fos.close(); + if (fos != null) fos.close(); } } finally { - fis.close(); + if (fis != null) fis.close(); } } @@ -870,4 +872,12 @@ public class ResourceLeaks { } } + public int tryWithResource() { + try (FileInputStream inputStream = new FileInputStream("paf.txt")) { + return inputStream.read(); + } catch (IOException e) { + return 0; + } + } + }