From 83f511107b255698514f9e070626b0371b5b11b8 Mon Sep 17 00:00:00 2001 From: Sam Blackshear Date: Fri, 13 May 2016 11:28:36 -0700 Subject: [PATCH] stop reporting handler leaks Reviewed By: jeremydubreil Differential Revision: D3295094 fbshipit-source-id: 038d933 --- infer/models/java/src/android/os/Handler.java | 37 ------------------- infer/src/backend/localise.ml | 5 +-- .../expected_outputs/ant_report.json | 5 --- .../expected_outputs/buck_report.json | 5 --- .../java/infer/ContextLeaks.java | 27 -------------- .../endtoend/java/infer/ContextLeaksTest.java | 1 - 6 files changed, 1 insertion(+), 79 deletions(-) delete mode 100644 infer/models/java/src/android/os/Handler.java diff --git a/infer/models/java/src/android/os/Handler.java b/infer/models/java/src/android/os/Handler.java deleted file mode 100644 index 928e13537..000000000 --- a/infer/models/java/src/android/os/Handler.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2015 - present Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ - -package android.os; - -import com.facebook.infer.models.InferUndefined; - -class Handler { - - // model queue of tasks using 1-recency abstraction - private static Runnable sFakeHandlerQueue; - - public final boolean postDelayed(Runnable r, long delayMillis) { - // model posting a delayed message as keeping a persistent reference to the Runnable - sFakeHandlerQueue = r; - return InferUndefined.boolean_undefined(); - } - - public final void removeCallbacks(Runnable r) { - if (r == sFakeHandlerQueue) - sFakeHandlerQueue = null; - } - - public final void removeCallbacks(Runnable r, Object token) { - removeCallbacks(r); - } - - public final void removeCallbacksAndMessages(Object token) { - sFakeHandlerQueue = null; - } -} diff --git a/infer/src/backend/localise.ml b/infer/src/backend/localise.ml index 1249daf00..aa78d171b 100644 --- a/infer/src/backend/localise.ml +++ b/infer/src/backend/localise.ml @@ -402,10 +402,7 @@ let java_unchecked_exn_desc proc_name exn_name pre_str : error_desc = let desc_context_leak pname context_typ fieldname leak_path : error_desc = let fld_str = Ident.fieldname_to_string fieldname in - let leak_root = - if fld_str = "android.os.Handler.sFakeHandlerQueue" - then " Runnable passed to Handler.postDelayed |->\n " - else " Static field " ^ fld_str ^ " |->\n " in + let leak_root = " Static field " ^ fld_str ^ " |->\n " in let leak_path_entry_to_str acc entry = let entry_str = match entry with | (Some fld, _) -> Ident.fieldname_to_string fld diff --git a/infer/tests/build_systems/expected_outputs/ant_report.json b/infer/tests/build_systems/expected_outputs/ant_report.json index 56589cd27..30b53189a 100644 --- a/infer/tests/build_systems/expected_outputs/ant_report.json +++ b/infer/tests/build_systems/expected_outputs/ant_report.json @@ -19,11 +19,6 @@ "file": "codetoanalyze/java/infer/ContextLeaks.java", "procedure": "ContextLeaks$Singleton ContextLeaks$Singleton.getInstance(Context)" }, - { - "bug_type": "CONTEXT_LEAK", - "file": "codetoanalyze/java/infer/ContextLeaks.java", - "procedure": "void ContextLeaks.indirectHandlerLeak()" - }, { "bug_type": "CONTEXT_LEAK", "file": "codetoanalyze/java/infer/ContextLeaks.java", diff --git a/infer/tests/build_systems/expected_outputs/buck_report.json b/infer/tests/build_systems/expected_outputs/buck_report.json index e99cf2f9c..fb40efc16 100644 --- a/infer/tests/build_systems/expected_outputs/buck_report.json +++ b/infer/tests/build_systems/expected_outputs/buck_report.json @@ -19,11 +19,6 @@ "file": "infer/tests/codetoanalyze/java/infer/ContextLeaks.java", "procedure": "ContextLeaks$Singleton ContextLeaks$Singleton.getInstance(Context)" }, - { - "bug_type": "CONTEXT_LEAK", - "file": "infer/tests/codetoanalyze/java/infer/ContextLeaks.java", - "procedure": "void ContextLeaks.indirectHandlerLeak()" - }, { "bug_type": "CONTEXT_LEAK", "file": "infer/tests/codetoanalyze/java/infer/ContextLeaks.java", diff --git a/infer/tests/codetoanalyze/java/infer/ContextLeaks.java b/infer/tests/codetoanalyze/java/infer/ContextLeaks.java index 3a9e00e1d..5fb3ace11 100644 --- a/infer/tests/codetoanalyze/java/infer/ContextLeaks.java +++ b/infer/tests/codetoanalyze/java/infer/ContextLeaks.java @@ -11,8 +11,6 @@ package codetoanalyze.java.infer; import android.content.Context; import android.app.Activity; -import android.os.Handler; - public class ContextLeaks extends Activity { @@ -92,29 +90,4 @@ public class ContextLeaks extends Activity { return Singleton.getInstance(this.getApplicationContext()); } - private Handler handler = new Handler(); - - public void indirectHandlerLeak() { - handlerLeak(); - } - - private void handlerLeak() { - Runnable r = - new Runnable() { - public void run() { - } - }; - handler.postDelayed(r, 10000); - } - - public void handlerNoLeak() { - Runnable r = - new Runnable() { - public void run() { - } - }; - handler.postDelayed(r, 10000); - handler.removeCallbacks(r); - } - } diff --git a/infer/tests/endtoend/java/infer/ContextLeaksTest.java b/infer/tests/endtoend/java/infer/ContextLeaksTest.java index af9202e98..f20a383e8 100644 --- a/infer/tests/endtoend/java/infer/ContextLeaksTest.java +++ b/infer/tests/endtoend/java/infer/ContextLeaksTest.java @@ -45,7 +45,6 @@ public class ContextLeaksTest { "nonStaticInnerClassLeak", "leakAfterInstanceFieldWrite", "singletonLeak", - "indirectHandlerLeak", "getInstance", }; assertThat(