diff --git a/infer/src/checkers/ThreadSafety.ml b/infer/src/checkers/ThreadSafety.ml index 06205e00f..e5281a49b 100644 --- a/infer/src/checkers/ThreadSafety.ml +++ b/infer/src/checkers/ThreadSafety.ml @@ -350,6 +350,9 @@ module TransferFunctions (CFG : ProcCfg.S) = struct | ("java.lang.Class" | "java.lang.reflect.Constructor"), "newInstance" -> (* reflection can perform allocations *) true + | "java.lang.Object" , "clone" -> + (* cloning is like allocation *) + true | "java.lang.ThreadLocal", "get" -> (* ThreadLocal prevents sharing between threads behind the scenes *) true diff --git a/infer/tests/codetoanalyze/java/threadsafety/Ownership.java b/infer/tests/codetoanalyze/java/threadsafety/Ownership.java index 664b791de..8dc8e90dd 100644 --- a/infer/tests/codetoanalyze/java/threadsafety/Ownership.java +++ b/infer/tests/codetoanalyze/java/threadsafety/Ownership.java @@ -376,6 +376,15 @@ public class Ownership { c.f = new Object(); } + void cloningAquiresOwnershipOk(){ + Ownership ow; + try { + ow = (Ownership) this.clone(); + ow.field = null; + } + catch (CloneNotSupportedException e) {} + } + }