diff --git a/infer/models/java/src/java/io/ByteArrayInputStream.java b/infer/models/java/src/java/io/ByteArrayInputStream.java new file mode 100644 index 000000000..f17d35503 --- /dev/null +++ b/infer/models/java/src/java/io/ByteArrayInputStream.java @@ -0,0 +1,11 @@ +package java.io; + +public class ByteArrayInputStream extends InputStream implements Closeable { + + public ByteArrayInputStream(byte[] buf) {} + + public ByteArrayInputStream(byte[] buf, int offset, int length) {} + + public void close() {} + +} diff --git a/infer/models/java/src/java/io/ByteArrayOutputStream.java b/infer/models/java/src/java/io/ByteArrayOutputStream.java new file mode 100644 index 000000000..b4a30643e --- /dev/null +++ b/infer/models/java/src/java/io/ByteArrayOutputStream.java @@ -0,0 +1,17 @@ +package java.io; + +public class ByteArrayOutputStream extends OutputStream implements Closeable { + + public ByteArrayOutputStream() {} + + public ByteArrayOutputStream(int size) {} + + @Override + public void write(int b) {} + + @Override + public void write(byte[] b, int off, int len) {} + + public void close() {} + +} diff --git a/infer/models/java/src/java/io/StringReader.java b/infer/models/java/src/java/io/StringReader.java new file mode 100644 index 000000000..6614c29e1 --- /dev/null +++ b/infer/models/java/src/java/io/StringReader.java @@ -0,0 +1,9 @@ +package java.io; + +public class StringReader implements Closeable { + + public StringReader(String s) {} + + public void close() {} + +} diff --git a/infer/tests/codetoanalyze/java/infer/CloseableAsResourceExample.java b/infer/tests/codetoanalyze/java/infer/CloseableAsResourceExample.java index 150393bc4..43e1edaf3 100644 --- a/infer/tests/codetoanalyze/java/infer/CloseableAsResourceExample.java +++ b/infer/tests/codetoanalyze/java/infer/CloseableAsResourceExample.java @@ -2,8 +2,11 @@ package codetoanalyze.java.infer; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.Closeable; import java.io.IOException; +import java.io.StringReader; public class CloseableAsResourceExample { @@ -79,4 +82,16 @@ public class CloseableAsResourceExample { s.mR.close(); } // should report a resource leak + void noNeedToCloseStringReader() { + StringReader stringReader = new StringReader("paf!"); + } + + void noNeedToCloseByteArrayOutputStream() { + ByteArrayOutputStream stream = new ByteArrayOutputStream(42); + } + + void noNeedToCloseByteArrayInputStream(byte[] array) { + ByteArrayInputStream stream = new ByteArrayInputStream(array); + } + }