[thread-safety] Add model and tests for SimpleArrayMap container.

Reviewed By: sblackshear

Differential Revision: D5208601

fbshipit-source-id: bbb78f1
master
Kyriakos Nikolaos Gkorogiannis 8 years ago committed by Facebook Github Bot
parent cf8d5483db
commit bee8e21633

@ -349,6 +349,9 @@ module TransferFunctions (CFG : ProcCfg.S) = struct
| ("android.util.SparseArray" | "android.support.v4.util.SparseArrayCompat"),
("append" | "clear" | "delete" | "put" | "remove" | "removeAt" | "removeAtRange"
| "setValueAt") -> true
| "android.support.v4.util.SimpleArrayMap",
("clear" | "ensureCapacity" | "put" | "putAll" | "remove" | "removeAt"
| "setValueAt") -> true
| "java.util.List", ("add" | "addAll" | "clear" | "remove" | "set") -> true
| "java.util.Map", ("clear" | "put" | "putAll" | "remove") -> true
| _ -> false in

@ -23,6 +23,7 @@ import javax.annotation.concurrent.ThreadSafe;
import android.support.v4.util.Pools.SynchronizedPool;
import android.support.v4.util.SparseArrayCompat;
import android.util.SparseArray;
import android.support.v4.util.SimpleArrayMap;
class ContainerWrapper {
private final List<Object> children = new ArrayList<Object>();
@ -236,4 +237,20 @@ class Containers {
sparseArray.put(0, new Object());
}
SimpleArrayMap<Integer, Integer> si_map = new SimpleArrayMap<Integer, Integer>();
synchronized public void addToSimpleArrayMapOk() {
si_map.put(1,1);
}
public void addToSimpleArrayMapBad(SimpleArrayMap<Integer, Integer> map) {
map.put(1,1);
}
// this should be a read/write race with addToSimpleArrayMapOk
public int FN_readSimpleArrayMap() {
return si_map.get(1);
}
}

@ -21,6 +21,7 @@ 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.addToSimpleArrayMapBad(SimpleArrayMap), 1, THREAD_SAFETY_VIOLATION, [container `&map` via call to `put`]
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`]

Loading…
Cancel
Save