[infer][java] add models for some common classes implementing Closeable without being resources

Summary:
@public
Modeling bypasses the Closeable as resource assumption for `java.io.StringReader`, `java.io.ByteArrayInputStream` and `java.io.ByteArrayOutputStream`.

Test Plan: Infer CI. Some resource leak should also disappear on Instagram.
master
jrm 10 years ago
parent c1db76f9a4
commit 11712caea9

@ -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() {}
}

@ -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() {}
}

@ -0,0 +1,9 @@
package java.io;
public class StringReader implements Closeable {
public StringReader(String s) {}
public void close() {}
}

@ -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);
}
}

Loading…
Cancel
Save