From 68a08a8a09e3c794e4f55dc05f75340a7e6d023e Mon Sep 17 00:00:00 2001 From: Nikos Gorogiannis Date: Fri, 16 Nov 2018 07:35:33 -0800 Subject: [PATCH] [starvation] stop reporting on AccountManager.setUserData Reviewed By: da319 Differential Revision: D13097076 fbshipit-source-id: 748acbe2b --- infer/src/concurrency/StarvationModels.ml | 6 +----- .../codetoanalyze/java/starvation/AccMgr.java | 6 ++++-- .../java/starvation/MyActivity.java | 10 +++++++--- .../codetoanalyze/java/starvation/issues.exp | 16 +++++++--------- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/infer/src/concurrency/StarvationModels.ml b/infer/src/concurrency/StarvationModels.ml index 46b425db6..4157cd885 100644 --- a/infer/src/concurrency/StarvationModels.ml +++ b/infer/src/concurrency/StarvationModels.ml @@ -109,11 +109,7 @@ let standard_matchers = ; methods= ["transact"] ; actuals_pred= (fun actuals -> - List.nth actuals 4 |> Option.value_map ~default:false ~f:HilExp.is_int_zero ) } - ; { default with - classname= "android.accounts.AccountManager" - ; methods= ["setUserData"] - ; search_superclasses= false } ] + List.nth actuals 4 |> Option.value_map ~default:false ~f:HilExp.is_int_zero ) } ] in let low_sev = [ { default with diff --git a/infer/tests/codetoanalyze/java/starvation/AccMgr.java b/infer/tests/codetoanalyze/java/starvation/AccMgr.java index 46fb43b96..21e5e5e77 100644 --- a/infer/tests/codetoanalyze/java/starvation/AccMgr.java +++ b/infer/tests/codetoanalyze/java/starvation/AccMgr.java @@ -15,13 +15,15 @@ class AccMgr { String key, data; Object lock; + // not OK: setUserData may cause stalls, but the general belief is that it's rare @UiThread - void onUiThreadBad() throws InterruptedException { + void onUiThreadOk() throws InterruptedException { am.setUserData(account, key, data); } + // ditto @UiThread - void lockOnUiThreadBad() throws InterruptedException { + void lockOnUiThreadOk() throws InterruptedException { synchronized (lock) { } } diff --git a/infer/tests/codetoanalyze/java/starvation/MyActivity.java b/infer/tests/codetoanalyze/java/starvation/MyActivity.java index 88f7f9af6..62e331487 100644 --- a/infer/tests/codetoanalyze/java/starvation/MyActivity.java +++ b/infer/tests/codetoanalyze/java/starvation/MyActivity.java @@ -5,16 +5,20 @@ * LICENSE file in the root directory of this source tree. */ -import android.accounts.AccountManager; import android.app.Activity; +import android.os.Binder; import android.os.Bundle; +import android.os.RemoteException; // test is for recognizing Activity lifecycle methods class MyActivity extends Activity { - AccountManager am; + Binder b; private void bad() { - am.setUserData(null, null, null); + try { + b.transact(0, null, null, 0); + } catch (RemoteException r) { + } } // overrides so no Bad suffixes diff --git a/infer/tests/codetoanalyze/java/starvation/issues.exp b/infer/tests/codetoanalyze/java/starvation/issues.exp index c91089ec2..786a2319b 100644 --- a/infer/tests/codetoanalyze/java/starvation/issues.exp +++ b/infer/tests/codetoanalyze/java/starvation/issues.exp @@ -1,5 +1,3 @@ -codetoanalyze/java/starvation/AccMgr.java, AccMgr.lockOnUiThreadBad():void, 25, STARVATION, no_bucket, ERROR, [[Trace 1] `void AccMgr.lockOnUiThreadBad()`,locks `this.AccMgr.lock` in class `AccMgr*`,[Trace 2] `void AccMgr.setUserDataUnderLock()`,locks `this.AccMgr.lock` in class `AccMgr*`,calls `void AccountManager.setUserData(Account,String,String)`,[Trace 1 on UI thread] `void AccMgr.lockOnUiThreadBad()`,`void AccMgr.lockOnUiThreadBad()` is annotated `UiThread`] -codetoanalyze/java/starvation/AccMgr.java, AccMgr.onUiThreadBad():void, 20, STARVATION, no_bucket, ERROR, [`void AccMgr.onUiThreadBad()`,calls `void AccountManager.setUserData(Account,String,String)`,[Trace on UI thread] `void AccMgr.onUiThreadBad()`,`void AccMgr.onUiThreadBad()` is annotated `UiThread`] codetoanalyze/java/starvation/AsyncTaskGet.java, AsyncTaskGet.lockOnUiThreadBad():void, 31, STARVATION, no_bucket, ERROR, [[Trace 1] `void AsyncTaskGet.lockOnUiThreadBad()`,locks `this.AsyncTaskGet.lock` in class `AsyncTaskGet*`,[Trace 2] `void AsyncTaskGet.taskGetUnderLock()`,locks `this.AsyncTaskGet.lock` in class `AsyncTaskGet*`,calls `Object AsyncTask.get()`,[Trace 1 on UI thread] `void AsyncTaskGet.lockOnUiThreadBad()`,`void AsyncTaskGet.lockOnUiThreadBad()` is annotated `UiThread`] codetoanalyze/java/starvation/AsyncTaskGet.java, AsyncTaskGet.taskGetOnUiThreadBad():void, 20, STARVATION, no_bucket, ERROR, [`void AsyncTaskGet.taskGetOnUiThreadBad()`,calls `Object AsyncTask.get()`,[Trace on UI thread] `void AsyncTaskGet.taskGetOnUiThreadBad()`,`void AsyncTaskGet.taskGetOnUiThreadBad()` is annotated `UiThread`] codetoanalyze/java/starvation/Binders.java, Binders.annotationBad():void, 35, STARVATION, no_bucket, ERROR, [`void Binders.annotationBad()`,Method call: `void Binders.doTransact()`,calls `boolean Binder.transact(int,Parcel,Parcel,int)`,[Trace on UI thread] `void Binders.annotationBad()`,`void Binders.annotationBad()` is annotated `UiThread`] @@ -28,13 +26,13 @@ codetoanalyze/java/starvation/Intraproc.java, Intraproc.intraBad(IntraprocA):voi codetoanalyze/java/starvation/LegacySync.java, LegacySync.onUiThreadOpBad():java.lang.Object, 25, STARVATION, no_bucket, ERROR, [[Trace 1] `Object LegacySync.onUiThreadOpBad()`,locks `this.LegacySync.table` in class `LegacySync*`,[Trace 2] `void LegacySync.notOnUiThreadSyncedBad()`,locks `this.LegacySync.table` in class `LegacySync*`,calls `Object Future.get()`,[Trace 1 on UI thread] `Object LegacySync.onUiThreadOpBad()`,`Object LegacySync.onUiThreadOpBad()` is annotated `UiThread`] codetoanalyze/java/starvation/MainThreadTest.java, AnnotatedClass.callTransactBad(MainThreadTest):void, 30, STARVATION, no_bucket, ERROR, [`void AnnotatedClass.callTransactBad(MainThreadTest)`,Method call: `void MainThreadTest.doTransact()`,calls `boolean Binder.transact(int,Parcel,Parcel,int)`,[Trace on UI thread] `void AnnotatedClass.callTransactBad(MainThreadTest)`,class `AnnotatedClass` is annotated `UiThread`] codetoanalyze/java/starvation/MainThreadTest.java, MainThreadTest.callTransactBad():void, 23, STARVATION, no_bucket, ERROR, [`void MainThreadTest.callTransactBad()`,Method call: `void MainThreadTest.doTransact()`,calls `boolean Binder.transact(int,Parcel,Parcel,int)`,[Trace on UI thread] `void MainThreadTest.callTransactBad()`,`void MainThreadTest.callTransactBad()` is annotated `UiThread`] -codetoanalyze/java/starvation/MyActivity.java, MyActivity.onCreate(android.os.Bundle):void, 24, STARVATION, no_bucket, ERROR, [`void MyActivity.onCreate(Bundle)`,Method call: `void MyActivity.bad()`,calls `void AccountManager.setUserData(Account,String,String)`,[Trace on UI thread] `void MyActivity.onCreate(Bundle)`,`void MyActivity.onCreate(Bundle)` is a standard UI-thread method] -codetoanalyze/java/starvation/MyActivity.java, MyActivity.onDestroy():void, 54, STARVATION, no_bucket, ERROR, [`void MyActivity.onDestroy()`,Method call: `void MyActivity.bad()`,calls `void AccountManager.setUserData(Account,String,String)`,[Trace on UI thread] `void MyActivity.onDestroy()`,`void MyActivity.onDestroy()` is a standard UI-thread method] -codetoanalyze/java/starvation/MyActivity.java, MyActivity.onPause():void, 44, STARVATION, no_bucket, ERROR, [`void MyActivity.onPause()`,Method call: `void MyActivity.bad()`,calls `void AccountManager.setUserData(Account,String,String)`,[Trace on UI thread] `void MyActivity.onPause()`,`void MyActivity.onPause()` is a standard UI-thread method] -codetoanalyze/java/starvation/MyActivity.java, MyActivity.onRestart():void, 34, STARVATION, no_bucket, ERROR, [`void MyActivity.onRestart()`,Method call: `void MyActivity.bad()`,calls `void AccountManager.setUserData(Account,String,String)`,[Trace on UI thread] `void MyActivity.onRestart()`,`void MyActivity.onRestart()` is a standard UI-thread method] -codetoanalyze/java/starvation/MyActivity.java, MyActivity.onResume():void, 39, STARVATION, no_bucket, ERROR, [`void MyActivity.onResume()`,Method call: `void MyActivity.bad()`,calls `void AccountManager.setUserData(Account,String,String)`,[Trace on UI thread] `void MyActivity.onResume()`,`void MyActivity.onResume()` is a standard UI-thread method] -codetoanalyze/java/starvation/MyActivity.java, MyActivity.onStart():void, 29, STARVATION, no_bucket, ERROR, [`void MyActivity.onStart()`,Method call: `void MyActivity.bad()`,calls `void AccountManager.setUserData(Account,String,String)`,[Trace on UI thread] `void MyActivity.onStart()`,`void MyActivity.onStart()` is a standard UI-thread method] -codetoanalyze/java/starvation/MyActivity.java, MyActivity.onStop():void, 49, STARVATION, no_bucket, ERROR, [`void MyActivity.onStop()`,Method call: `void MyActivity.bad()`,calls `void AccountManager.setUserData(Account,String,String)`,[Trace on UI thread] `void MyActivity.onStop()`,`void MyActivity.onStop()` is a standard UI-thread method] +codetoanalyze/java/starvation/MyActivity.java, MyActivity.onCreate(android.os.Bundle):void, 28, STARVATION, no_bucket, ERROR, [`void MyActivity.onCreate(Bundle)`,Method call: `void MyActivity.bad()`,calls `boolean Binder.transact(int,Parcel,Parcel,int)`,[Trace on UI thread] `void MyActivity.onCreate(Bundle)`,`void MyActivity.onCreate(Bundle)` is a standard UI-thread method] +codetoanalyze/java/starvation/MyActivity.java, MyActivity.onDestroy():void, 58, STARVATION, no_bucket, ERROR, [`void MyActivity.onDestroy()`,Method call: `void MyActivity.bad()`,calls `boolean Binder.transact(int,Parcel,Parcel,int)`,[Trace on UI thread] `void MyActivity.onDestroy()`,`void MyActivity.onDestroy()` is a standard UI-thread method] +codetoanalyze/java/starvation/MyActivity.java, MyActivity.onPause():void, 48, STARVATION, no_bucket, ERROR, [`void MyActivity.onPause()`,Method call: `void MyActivity.bad()`,calls `boolean Binder.transact(int,Parcel,Parcel,int)`,[Trace on UI thread] `void MyActivity.onPause()`,`void MyActivity.onPause()` is a standard UI-thread method] +codetoanalyze/java/starvation/MyActivity.java, MyActivity.onRestart():void, 38, STARVATION, no_bucket, ERROR, [`void MyActivity.onRestart()`,Method call: `void MyActivity.bad()`,calls `boolean Binder.transact(int,Parcel,Parcel,int)`,[Trace on UI thread] `void MyActivity.onRestart()`,`void MyActivity.onRestart()` is a standard UI-thread method] +codetoanalyze/java/starvation/MyActivity.java, MyActivity.onResume():void, 43, STARVATION, no_bucket, ERROR, [`void MyActivity.onResume()`,Method call: `void MyActivity.bad()`,calls `boolean Binder.transact(int,Parcel,Parcel,int)`,[Trace on UI thread] `void MyActivity.onResume()`,`void MyActivity.onResume()` is a standard UI-thread method] +codetoanalyze/java/starvation/MyActivity.java, MyActivity.onStart():void, 33, STARVATION, no_bucket, ERROR, [`void MyActivity.onStart()`,Method call: `void MyActivity.bad()`,calls `boolean Binder.transact(int,Parcel,Parcel,int)`,[Trace on UI thread] `void MyActivity.onStart()`,`void MyActivity.onStart()` is a standard UI-thread method] +codetoanalyze/java/starvation/MyActivity.java, MyActivity.onStop():void, 53, STARVATION, no_bucket, ERROR, [`void MyActivity.onStop()`,Method call: `void MyActivity.bad()`,calls `boolean Binder.transact(int,Parcel,Parcel,int)`,[Trace on UI thread] `void MyActivity.onStop()`,`void MyActivity.onStop()` is a standard UI-thread method] codetoanalyze/java/starvation/NonBlk.java, NonBlk.deadlockABBad():void, 33, DEADLOCK, no_bucket, ERROR, [[Trace 1] `void NonBlk.deadlockABBad()`,locks `this` in class `NonBlk*`,locks `this.NonBlk.future` in class `NonBlk*`,[Trace 2] `void NonBlk.deadlockBABad()`,locks `this.NonBlk.future` in class `NonBlk*`,locks `this` in class `NonBlk*`] codetoanalyze/java/starvation/ObjWait.java, ObjWait.indirectWaitOnMainWithoutTimeoutBad():void, 46, STARVATION, no_bucket, ERROR, [[Trace 1] `void ObjWait.indirectWaitOnMainWithoutTimeoutBad()`,locks `this.ObjWait.lock` in class `ObjWait*`,[Trace 2] `void ObjWait.lockAndWaitOnAnyWithoutTimeoutBad()`,locks `this.ObjWait.lock` in class `ObjWait*`,calls `void Object.wait()`,[Trace 1 on UI thread] `void ObjWait.indirectWaitOnMainWithoutTimeoutBad()`,`void ObjWait.indirectWaitOnMainWithoutTimeoutBad()` is annotated `UiThread`] codetoanalyze/java/starvation/ObjWait.java, ObjWait.waitOnMainWithExcessiveTimeout1Bad():void, 31, STARVATION, no_bucket, ERROR, [`void ObjWait.waitOnMainWithExcessiveTimeout1Bad()`,calls `void Object.wait(long)`,[Trace on UI thread] `void ObjWait.waitOnMainWithExcessiveTimeout1Bad()`,`void ObjWait.waitOnMainWithExcessiveTimeout1Bad()` is annotated `UiThread`]