[thread-safety] container models for SparseArray/SparseArrayCompat

Reviewed By: ngorogiannis

Differential Revision: D5176946

fbshipit-source-id: 55a9ce3
master
Sam Blackshear 8 years ago committed by Facebook Github Bot
parent 56201964ca
commit 2089cd8a34

@ -346,6 +346,9 @@ module TransferFunctions (CFG : ProcCfg.S) = struct
let typename = Typ.Name.Java.from_string (Typ.Procname.java_get_class_name java_pname) in
let is_container_write_ typename _ =
match Typ.Name.name typename, Typ.Procname.java_get_method java_pname with
| ("android.util.SparseArray" | "android.support.v4.util.SparseArrayCompat"),
("append" | "clear" | "delete" | "put" | "remove" | "removeAt" | "removeAtRange"
| "setValueAt") -> true
| "java.util.List", ("add" | "addAll" | "clear" | "remove" | "set") -> true
| "java.util.Map", ("clear" | "put" | "putAll" | "remove") -> true
| _ -> false in

@ -21,6 +21,8 @@ import java.util.concurrent.CopyOnWriteArrayList;
import javax.annotation.concurrent.ThreadSafe;
import android.support.v4.util.Pools.SynchronizedPool;
import android.support.v4.util.SparseArrayCompat;
import android.util.SparseArray;
class ContainerWrapper {
private final List<Object> children = new ArrayList<Object>();
@ -216,4 +218,22 @@ class Containers {
addOrCreateList(list);
}
void addToSparseArrayCompatOk() {
SparseArrayCompat sparseArray = new SparseArrayCompat();
sparseArray.put(0, new Object());
}
public void addToSparseArrayCompatBad(SparseArrayCompat sparseArray) {
sparseArray.put(0, new Object());
}
public void addToSparseArrayOk() {
SparseArray sparseArray = new SparseArray();
sparseArray.put(0, new Object());
}
public void addToSparseArrayBad(SparseArray sparseArray) {
sparseArray.put(0, new Object());
}
}

@ -21,6 +21,8 @@ codetoanalyze/java/threadsafety/Builders.java, void TopLevelBuilder.setG(String)
codetoanalyze/java/threadsafety/Constructors.java, Constructors Constructors.singletonBad(), 2, THREAD_SAFETY_VIOLATION, [call to Constructors.<init>(Object),access to `Constructors.staticField`]
codetoanalyze/java/threadsafety/Constructors.java, Constructors.<init>(), 1, THREAD_SAFETY_VIOLATION, [access to `Constructors.staticField`]
codetoanalyze/java/threadsafety/Constructors.java, Constructors.<init>(Constructors), 1, THREAD_SAFETY_VIOLATION, [access to `Constructors.field`]
codetoanalyze/java/threadsafety/Containers.java, void Containers.addToSparseArrayBad(SparseArray), 1, THREAD_SAFETY_VIOLATION, [container `&sparseArray` via call to `put`]
codetoanalyze/java/threadsafety/Containers.java, void Containers.addToSparseArrayCompatBad(SparseArrayCompat), 1, THREAD_SAFETY_VIOLATION, [container `&sparseArray` via call to `put`]
codetoanalyze/java/threadsafety/Containers.java, void Containers.containerWrapperUnownedWriteBad(Object), 1, THREAD_SAFETY_VIOLATION, [container `codetoanalyze.java.checkers.ContainerWrapper.children` via call to `add`,container `codetoanalyze.java.checkers.ContainerWrapper.children` via call to `add`,container `codetoanalyze.java.checkers.ContainerWrapper.children` via call to `add`]
codetoanalyze/java/threadsafety/Containers.java, void Containers.listAddAllBad(Collection), 1, THREAD_SAFETY_VIOLATION, [container `codetoanalyze.java.checkers.Containers.mList` via call to `addAll`]
codetoanalyze/java/threadsafety/Containers.java, void Containers.listAddBad1(String), 1, THREAD_SAFETY_VIOLATION, [container `codetoanalyze.java.checkers.Containers.mList` via call to `add`]

Loading…
Cancel
Save