[infer][java] attach the file attribute of Cursor to the object itself, not a field.

Summary:
@public
Attaching the resource attribute to the object allows to more easily remove this attribute during the symbolic execution when the resource is passed as a argument, e.g. with `res.close()` or when this resource is passed around via a skipped function.

Test Plan: Infer CI.
master
jrm 10 years ago
parent d7a4474d90
commit 762f572506

@ -6,9 +6,14 @@
package android.database;
import java.io.Closeable;
import com.facebook.infer.models.InferUndefined;
import android.database.sqlite.SQLiteCursor;
public class Cursor {
public class Cursor implements Closeable {
public void close() {
if (this instanceof SQLiteCursor) {
@ -16,4 +21,34 @@ public class Cursor {
}
}
public int getInt(int position) {
return InferUndefined.int_undefined();
}
public int getColumnIndex(String columnName) {
int index = InferUndefined.int_undefined();
while (index < -1) {}
return index;
}
public boolean move(int position) {
return InferUndefined.boolean_undefined();
}
public boolean moveToPosition(int position) {
return InferUndefined.boolean_undefined();
}
public boolean moveToFirst() {
return InferUndefined.boolean_undefined();
}
public boolean moveToNext() {
return InferUndefined.boolean_undefined();
}
public boolean moveToLast() {
return InferUndefined.boolean_undefined();
}
}

@ -23,8 +23,6 @@ import com.facebook.infer.models.InferUndefined;
public class SQLiteCursor extends Cursor {
private String mEditTable;
@Deprecated
public SQLiteCursor(SQLiteDatabase db, SQLiteCursorDriver driver,
String editTable, SQLiteQuery query) {
@ -33,8 +31,7 @@ public class SQLiteCursor extends Cursor {
public SQLiteCursor(SQLiteCursorDriver driver, String editTable, SQLiteQuery query) {
mEditTable = new String();
InferBuiltins.__set_file_attribute(mEditTable);
InferBuiltins.__set_file_attribute(this);
}
@ -48,6 +45,7 @@ public class SQLiteCursor extends Cursor {
}
public void close() {
InferBuiltins.__set_mem_attribute(mEditTable);
InferBuiltins.__set_mem_attribute(this);
}
}

@ -213,4 +213,12 @@ public class CursorLeaks {
Cursor c = new NamedCursor(cursor, "abc");
c.close();
}
native NamedCursor createWrapper(Cursor cursor);
public NamedCursor cursorAttachedTheWrapper(SQLiteDatabase sqLiteDatabase) {
Cursor cursor = sqLiteDatabase.query("events", null, null, null, null, null, null);
return createWrapper(cursor);
}
}

Loading…
Cancel
Save