[thread-safety] account for ownership via reflective allocation

Reviewed By: jeremydubreil

Differential Revision: D4722711

fbshipit-source-id: 3b52ef5
master
Sam Blackshear 8 years ago committed by Facebook Github Bot
parent e023dddba2
commit 9066e5bd08

@ -320,6 +320,9 @@ module TransferFunctions (CFG : ProcCfg.S) = struct
| "javax.inject.Provider", "get" ->
(* in dependency injection, the library allocates fresh values behind the scenes *)
true
| ("java.lang.Class" | "java.lang.reflect.Constructor"), "newInstance" ->
(* reflection can perform allocations *)
true
| "java.lang.ThreadLocal", "get" ->
(* ThreadLocal prevents sharing between threads behind the scenes *)
true

@ -9,6 +9,10 @@
package codetoanalyze.java.checkers;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import javax.annotation.concurrent.ThreadSafe;
import javax.inject.Inject;
import javax.inject.Provider;
@ -353,6 +357,20 @@ public class Ownership {
castThenReturn(o).f = new Object();
}
void ownViaReflectionOk1() throws InstantiationException, IllegalAccessException {
Class<Obj> oClass = Obj.class;
Obj o = oClass.newInstance();
o.f = new Object();
}
void ownViaReflectionOk2()
throws IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException {
Class<Obj> oClass = Obj.class;
Constructor<Obj> oConstructor = oClass.getConstructor();
Obj o = oConstructor.newInstance();
o.f = new Object();
}
}

Loading…
Cancel
Save