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; package android.database;
import java.io.Closeable;
import com.facebook.infer.models.InferUndefined; import com.facebook.infer.models.InferUndefined;
import com.facebook.infer.models.InferBuiltins; import com.facebook.infer.models.InferBuiltins;
import android.database.sqlite.SQLiteCursor; public class Cursor {
public class Cursor implements Closeable {
public void close() { public void close() {
if (this instanceof SQLiteCursor) { InferBuiltins.__set_mem_attribute(this);
((SQLiteCursor) this).close();
}
} }
public int getInt(int position) { public int getInt(int position) {

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

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

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

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

@ -11,47 +11,16 @@ package com.squareup.okhttp.internal;
import com.facebook.infer.models.InferUndefined; import com.facebook.infer.models.InferUndefined;
import java.io.Closeable;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
public class StrictLineReader implements Closeable { public class StrictLineReader {
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 String readLine() throws IOException { public String readLine() throws IOException {
return InferUndefined.can_throw_ioexception_string(); return InferUndefined.can_throw_ioexception_string();
} }
public int readInt() throws IOException { public int readInt() throws IOException {
return InferUndefined.can_throw_ioexception_int(); return InferUndefined.can_throw_ioexception_int();
} }
} }

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

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

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

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

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

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

Loading…
Cancel
Save