diff --git a/infer/models/java/src/java/io/FilterInputStream.java b/infer/models/java/src/java/io/FilterInputStream.java index 5cab86568..e682588f1 100644 --- a/infer/models/java/src/java/io/FilterInputStream.java +++ b/infer/models/java/src/java/io/FilterInputStream.java @@ -28,9 +28,13 @@ public class FilterInputStream extends InputStream { } public void close() throws IOException { - if (in != null) - if (in instanceof FileInputStream) + if (in != null) { + if (in instanceof FileInputStream) { ((FileInputStream) in).close(); + } else { + in.close(); + } + } } public int read() throws IOException { diff --git a/infer/tests/codetoanalyze/java/infer/FilterInputStreamLeaks.java b/infer/tests/codetoanalyze/java/infer/FilterInputStreamLeaks.java index 1b12e0e80..351522c6d 100644 --- a/infer/tests/codetoanalyze/java/infer/FilterInputStreamLeaks.java +++ b/infer/tests/codetoanalyze/java/infer/FilterInputStreamLeaks.java @@ -10,11 +10,7 @@ package codetoanalyze.java.infer; -import java.io.BufferedInputStream; -import java.io.DataInputStream; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.PushbackInputStream; +import java.io.*; import java.security.DigestInputStream; import java.util.zip.CheckedInputStream; import java.util.zip.DeflaterInputStream; @@ -263,4 +259,10 @@ public class FilterInputStreamLeaks { if (pms != null) pms.close(); } } + + public void twoLevelWrapperNoLeak(File file) throws IOException { + DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(file))); + in.close(); + } + }