Some cleanup of the models where calls to instanceof are not necessary

Summary: Removes some calls to `instanceof` that don't look necessary.

Reviewed By: sblackshear

Differential Revision: D3183253

fb-gh-sync-id: 2ffd36d
fbshipit-source-id: 2ffd36d
master
jrm 9 years ago committed by Facebook Github Bot 6
parent 596d8338ee
commit 4b6d754164

@ -10,20 +10,13 @@
package android.database;
import java.io.Closeable;
import com.facebook.infer.models.InferUndefined;
import com.facebook.infer.models.InferBuiltins;
import android.database.sqlite.SQLiteCursor;
public class Cursor implements Closeable {
public class Cursor {
public void close() {
if (this instanceof SQLiteCursor) {
((SQLiteCursor) this).close();
}
InferBuiltins.__set_mem_attribute(this);
}
public int getInt(int position) {

@ -10,36 +10,21 @@
package com.facebook.infer.models;
import com.squareup.okhttp.internal.StrictLineReader;
import java.io.*;
import java.io.Closeable;
public final class InferCloseables {
private InferCloseables() {
}
private InferCloseables() {
}
public static void close(Closeable closeable, boolean swallowIOException)
throws IOException {
if (closeable == null) return;
if (closeable instanceof InputStream) {
((InputStream) closeable).close();
} else if (closeable instanceof OutputStream) {
((OutputStream) closeable).close();
} else if (closeable instanceof Reader) {
((Reader) closeable).close();
} else if (closeable instanceof Writer) {
((Writer) closeable).close();
} else if (closeable instanceof StrictLineReader) {
((StrictLineReader) closeable).close();
}
public static void close(Closeable closeable) {
if (closeable != null) {
InferBuiltins.__set_mem_attribute(closeable);
}
}
public static void closeQuietly(Closeable closeable) {
try {
close(closeable, true);
} catch (IOException e) {
}
}
public static void closeQuietly(Closeable closeable) {
close(closeable);
}
}

@ -10,8 +10,6 @@
package com.facebook.infer.models;
import com.facebook.infer.models.InferBuiltins;
import java.io.IOException;
import java.net.SocketException;
import java.sql.SQLException;

@ -9,8 +9,8 @@
package com.fasterxml.jackson.core;
import com.facebook.infer.models.InferBuiltins;
import com.facebook.infer.models.InferUndefined;
import com.fasterxml.jackson.core.json.UTF8StreamJsonParser;
import java.io.Closeable;
import java.io.IOException;
@ -19,9 +19,8 @@ public abstract class JsonParser
implements Closeable, Versioned {
public void close() throws IOException {
if (this instanceof UTF8StreamJsonParser) {
((UTF8StreamJsonParser) this).close();
}
InferBuiltins.__set_mem_attribute(this);
InferUndefined.can_throw_ioexception_void();
}
private void throwExceptions()

@ -18,7 +18,7 @@ import java.io.IOException;
public final class Closeables {
public static void close(Closeable closeable, boolean swallowIOException) throws IOException {
InferCloseables.close(closeable, swallowIOException);
InferCloseables.close(closeable);
if (!swallowIOException)
InferUndefined.can_throw_ioexception_void();
}

@ -11,47 +11,16 @@ package com.squareup.okhttp.internal;
import com.facebook.infer.models.InferUndefined;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
public class StrictLineReader implements Closeable {
private InputStream in;
private Charset charset;
private byte[] buf;
public StrictLineReader(InputStream in, Charset charset) {
this(in, 8192, charset);
}
public StrictLineReader(InputStream in, int capacity, Charset charset) {
if (in == null) {
throw new NullPointerException();
}
if (capacity < 0) {
throw new IllegalArgumentException("capacity <= 0");
}
this.in = in;
this.charset = charset;
buf = new byte[capacity];
}
public void close() throws IOException {
in.close();
InferUndefined.can_throw_ioexception_void();
}
public class StrictLineReader {
public String readLine() throws IOException {
return InferUndefined.can_throw_ioexception_string();
}
public int readInt() throws IOException {
return InferUndefined.can_throw_ioexception_int();
}
}

@ -24,8 +24,13 @@ public class BufferedReader extends Reader {
}
public void close() throws IOException {
if (in instanceof InputStreamReader)
if (in instanceof InputStreamReader) {
((InputStreamReader) in).close();
} else if (in instanceof BufferedReader) {
((BufferedReader) in).close();
} else {
in.close();
}
}
public int read() throws IOException {

@ -45,6 +45,10 @@ public class FileInputStream extends InputStream {
init();
}
public void close() throws IOException {
super.close();
}
public FileChannel getChannel() {
channel = new FileChannelImpl(this, fd, InferUndefined.int_undefined());
return channel;
@ -54,11 +58,6 @@ public class FileInputStream extends InputStream {
return InferUndefined.can_throw_ioexception_int();
}
public void close() throws IOException {
InferBuiltins.__set_mem_attribute(this);
InferUndefined.can_throw_ioexception_void();
}
@Override
public int read() throws IOException {
return InferUndefined.can_throw_ioexception_int();

@ -19,10 +19,6 @@ public class FilterInputStream extends InputStream {
this.in = in;
}
public FilterInputStream() {
super();
}
public int available() throws IOException {
return InferUndefined.can_throw_ioexception_int();
}
@ -31,6 +27,8 @@ public class FilterInputStream extends InputStream {
if (in != null) {
if (in instanceof FileInputStream) {
((FileInputStream) in).close();
} else if (in instanceof BufferedInputStream) {
((FilterInputStream) in).close();
} else {
in.close();
}
@ -53,7 +51,6 @@ public class FilterInputStream extends InputStream {
InferUndefined.can_throw_ioexception_void();
}
public long skip(long n) throws IOException {
return InferUndefined.can_throw_ioexception_long();
}

@ -26,6 +26,8 @@ public class FilterOutputStream extends OutputStream {
if (out != null) {
if (out instanceof FileOutputStream) {
((FileOutputStream) out).close();
} else {
out.close();
}
}
}

@ -9,16 +9,14 @@
package java.io;
import com.facebook.infer.models.InferBuiltins;
import com.facebook.infer.models.InferUndefined;
public class InputStream implements Closeable {
public class InputStream {
public void close() throws IOException {
if (this instanceof FileInputStream) {
((FileInputStream) this).close();
} else if (this instanceof FilterInputStream) {
((FilterInputStream) this).close();
}
InferBuiltins.__set_mem_attribute(this);
InferUndefined.can_throw_ioexception_void();
}
public int read() throws IOException {

@ -9,18 +9,14 @@
package java.io;
import com.facebook.infer.models.InferBuiltins;
import com.facebook.infer.models.InferUndefined;
public abstract class Reader implements Closeable {
public abstract class Reader {
public void close() throws IOException {
if (this instanceof InputStreamReader) {
((InputStreamReader) this).close();
} else if (this instanceof BufferedReader) {
((BufferedReader) this).close();
} else if (this instanceof FilterReader) {
((FilterReader) this).close();
}
InferBuiltins.__set_mem_attribute(this);
InferUndefined.can_throw_ioexception_void();
}
public int read() throws IOException {

Loading…
Cancel
Save