[thread-safety] assume findViewById returns ownership

Reviewed By: jaegs

Differential Revision: D4901258

fbshipit-source-id: a4c4dab
master
Sam Blackshear 8 years ago committed by Facebook Github Bot
parent 19e490dbd2
commit 3c7361a83d

@ -296,6 +296,9 @@ module TransferFunctions (CFG : ProcCfg.S) = struct
| "java.lang.ThreadLocal", "get" ->
(* ThreadLocal prevents sharing between threads behind the scenes *)
true
| ("android.app.Activity" | "android.view.View"), "findViewById" ->
(* assume findViewById creates fresh View's (note: not always true) *)
true
| "android.support.v4.util.Pools$SynchronizedPool", "acquire" ->
(* a pool should own all of its objects *)
true

@ -11,11 +11,18 @@ package codetoanalyze.java.checkers;
import javax.annotation.concurrent.ThreadSafe;
import android.app.Activity;
import android.content.Context;
import android.content.res.AssetManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.view.View;
import android.util.DisplayMetrics;
class MyActivity extends Activity {
}
class MyResources extends Resources {
public MyResources(AssetManager assets, DisplayMetrics metrics, Configuration config) {
@ -24,6 +31,16 @@ class MyResources extends Resources {
}
class MyView extends View {
boolean mField;
public MyView(Context c) {
super(c);
}
}
@ThreadSafe
public class AndroidModels {
@ -48,4 +65,14 @@ public class AndroidModels {
mField = mResources.getConfiguration();
}
public void findViewByIdOk1(MyView view) {
MyView subview = (MyView) view.findViewById(-1);
subview.mField = true; // ok;
}
public void findViewByIdOk2(MyActivity activity) {
MyView view = (MyView) activity.findViewById(-1);
view.mField = true; // ok;
}
}

Loading…
Cancel
Save