From bee8e21633480160526109f645ac6456d748f353 Mon Sep 17 00:00:00 2001 From: Kyriakos Nikolaos Gkorogiannis Date: Thu, 8 Jun 2017 07:58:46 -0700 Subject: [PATCH] [thread-safety] Add model and tests for SimpleArrayMap container. Reviewed By: sblackshear Differential Revision: D5208601 fbshipit-source-id: bbb78f1 --- infer/src/checkers/ThreadSafety.ml | 3 +++ .../java/threadsafety/Containers.java | 17 +++++++++++++++++ .../codetoanalyze/java/threadsafety/issues.exp | 1 + 3 files changed, 21 insertions(+) diff --git a/infer/src/checkers/ThreadSafety.ml b/infer/src/checkers/ThreadSafety.ml index 01d70a5f0..cf17fcfcd 100644 --- a/infer/src/checkers/ThreadSafety.ml +++ b/infer/src/checkers/ThreadSafety.ml @@ -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 diff --git a/infer/tests/codetoanalyze/java/threadsafety/Containers.java b/infer/tests/codetoanalyze/java/threadsafety/Containers.java index 2f03911af..d188c206e 100644 --- a/infer/tests/codetoanalyze/java/threadsafety/Containers.java +++ b/infer/tests/codetoanalyze/java/threadsafety/Containers.java @@ -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 children = new ArrayList(); @@ -236,4 +237,20 @@ class Containers { sparseArray.put(0, new Object()); } + SimpleArrayMap si_map = new SimpleArrayMap(); + + synchronized public void addToSimpleArrayMapOk() { + si_map.put(1,1); + } + + public void addToSimpleArrayMapBad(SimpleArrayMap map) { + map.put(1,1); + } + + // this should be a read/write race with addToSimpleArrayMapOk + public int FN_readSimpleArrayMap() { + return si_map.get(1); + } + + } diff --git a/infer/tests/codetoanalyze/java/threadsafety/issues.exp b/infer/tests/codetoanalyze/java/threadsafety/issues.exp index 3a4b8927b..13d64ca2e 100644 --- a/infer/tests/codetoanalyze/java/threadsafety/issues.exp +++ b/infer/tests/codetoanalyze/java/threadsafety/issues.exp @@ -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.(Object),access to `Constructors.staticField`] codetoanalyze/java/threadsafety/Constructors.java, Constructors.(), 1, THREAD_SAFETY_VIOLATION, [access to `Constructors.staticField`] codetoanalyze/java/threadsafety/Constructors.java, Constructors.(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`]