From 274851fc5336119adbdb7bbdaa61e22d57ff708a Mon Sep 17 00:00:00 2001 From: Jeremy Dubreil Date: Wed, 9 Nov 2016 11:42:41 -0800 Subject: [PATCH] [infer][java] mark all methods as defined Summary: Mark native methods as defined so that the analysis generates a summary for those methods. When analyzing Java projects compiled with Buck, the summaries for the dependencies methods of are retrieved from the classpath. In this case, having access to the summary is useful to access the attributes of a callee when the callee is part of a, previously analyzed, Buck target. Reviewed By: sblackshear Differential Revision: D4141362 fbshipit-source-id: 75888c8 --- infer/src/java/jFrontend.ml | 22 +++++++++---------- .../tests/codetoanalyze/java/infer/issues.exp | 14 ++++++++++++ 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/infer/src/java/jFrontend.ml b/infer/src/java/jFrontend.ml index c58647576..1c5eece75 100644 --- a/infer/src/java/jFrontend.ml +++ b/infer/src/java/jFrontend.ml @@ -91,8 +91,7 @@ let add_cmethod source_file program linereader icfg cm proc_name = let context = JContext.create_context icfg procdesc impl cn source_file program in let method_body_nodes = Array.mapi (JTrans.instruction context) instrs in - add_edges context start_node exn_node [exit_node] method_body_nodes impl false; - Cg.add_defined_node icfg.JContext.cg proc_name + add_edges context start_node exn_node [exit_node] method_body_nodes impl false let path_of_cached_classname cn = @@ -142,15 +141,16 @@ let create_icfg source_file linereader program icfg cn node = try (* each procedure has different scope: start names from id 0 *) Ident.NameGenerator.reset (); - match m with - | Javalib.AbstractMethod am -> - ignore (JTrans.create_am_procdesc program icfg am proc_name); - (* TODO #4040807: investigate why we need to mark asbtract methods as defined *) - Cg.add_defined_node icfg.JContext.cg proc_name - | Javalib.ConcreteMethod cm when JTrans.is_java_native cm -> - ignore (JTrans.create_native_procdesc program icfg cm proc_name) - | Javalib.ConcreteMethod cm -> - add_cmethod source_file program linereader icfg cm proc_name + begin + match m with + | Javalib.AbstractMethod am -> + ignore (JTrans.create_am_procdesc program icfg am proc_name) + | Javalib.ConcreteMethod cm when JTrans.is_java_native cm -> + ignore (JTrans.create_native_procdesc program icfg cm proc_name) + | Javalib.ConcreteMethod cm -> + add_cmethod source_file program linereader icfg cm proc_name + end; + Cg.add_defined_node icfg.JContext.cg proc_name with JBasics.Class_structure_error _ -> L.do_err "create_icfg raised JBasics.Class_structure_error on %a@." diff --git a/infer/tests/codetoanalyze/java/infer/issues.exp b/infer/tests/codetoanalyze/java/infer/issues.exp index c6799cfff..78d169d33 100644 --- a/infer/tests/codetoanalyze/java/infer/issues.exp +++ b/infer/tests/codetoanalyze/java/infer/issues.exp @@ -53,12 +53,22 @@ ContextLeaks.java, void ContextLeaks.indirectLeak(), 4, CONTEXT_LEAK ContextLeaks.java, void ContextLeaks.leakAfterInstanceFieldWrite(), 3, CONTEXT_LEAK ContextLeaks.java, void ContextLeaks.nonStaticInnerClassLeak(), 2, CONTEXT_LEAK CursorLeaks.java, int CursorLeaks.completeDownloadNotClosed(DownloadManager), 8, RESOURCE_LEAK +CursorLeaks.java, int CursorLeaks.cursorClosed(SQLiteDatabase), 7, ANALYSIS_STOPS +CursorLeaks.java, int CursorLeaks.cursorClosed(SQLiteDatabase), 7, CLASS_CAST_EXCEPTION CursorLeaks.java, int CursorLeaks.cursorNotClosed(SQLiteDatabase), 4, RESOURCE_LEAK +CursorLeaks.java, int CursorLeaks.getBucketCountClosed(), 13, ANALYSIS_STOPS +CursorLeaks.java, int CursorLeaks.getBucketCountClosed(), 13, CLASS_CAST_EXCEPTION CursorLeaks.java, int CursorLeaks.getBucketCountNotClosed(), 10, RESOURCE_LEAK +CursorLeaks.java, int CursorLeaks.getImageCountHelperClosed(String), 14, ANALYSIS_STOPS +CursorLeaks.java, int CursorLeaks.getImageCountHelperClosed(String), 14, CLASS_CAST_EXCEPTION CursorLeaks.java, int CursorLeaks.getImageCountHelperNotClosed(String), 13, RESOURCE_LEAK +CursorLeaks.java, void CursorLeaks.loadPrefsFromContentProviderClosed(), 12, ANALYSIS_STOPS +CursorLeaks.java, void CursorLeaks.loadPrefsFromContentProviderClosed(), 12, CLASS_CAST_EXCEPTION CursorLeaks.java, void CursorLeaks.loadPrefsFromContentProviderClosed(), 3, NULL_TEST_AFTER_DEREFERENCE CursorLeaks.java, void CursorLeaks.loadPrefsFromContentProviderNotClosed(), 11, RESOURCE_LEAK CursorLeaks.java, void CursorLeaks.loadPrefsFromContentProviderNotClosed(), 3, NULL_TEST_AFTER_DEREFERENCE +CursorLeaks.java, void CursorLeaks.queryUVMLegacyDbClosed(), 4, ANALYSIS_STOPS +CursorLeaks.java, void CursorLeaks.queryUVMLegacyDbClosed(), 4, CLASS_CAST_EXCEPTION CursorLeaks.java, void CursorLeaks.queryUVMLegacyDbNotClosed(), 4, RESOURCE_LEAK CursorLeaks.java, void CursorLeaks.queryUVMLegacyDbNotClosed(), 4, RETURN_VALUE_IGNORED DivideByZero.java, int DivideByZero.callDivideByZeroInterProc(), 1, DIVIDE_BY_ZERO @@ -163,6 +173,8 @@ NullPointerExceptions.java, String NullPointerExceptions.testSystemGetPropertyAr NullPointerExceptions.java, String NullPointerExceptions.tryLockThrows(FileChannel), 6, ANALYSIS_STOPS NullPointerExceptions.java, String NullPointerExceptions.tryLockThrows(FileChannel), 6, NULL_DEREFERENCE NullPointerExceptions.java, int NullPointerExceptions.NPEvalueOfFromHashmapBad(HashMap,int), 1, NULL_DEREFERENCE +NullPointerExceptions.java, int NullPointerExceptions.cursorQueryShouldNotReturnNull(SQLiteDatabase), 6, ANALYSIS_STOPS +NullPointerExceptions.java, int NullPointerExceptions.cursorQueryShouldNotReturnNull(SQLiteDatabase), 6, CLASS_CAST_EXCEPTION NullPointerExceptions.java, int NullPointerExceptions.nullListFiles(String), 3, NULL_DEREFERENCE NullPointerExceptions.java, int NullPointerExceptions.nullPointerException(), 2, ANALYSIS_STOPS NullPointerExceptions.java, int NullPointerExceptions.nullPointerException(), 2, NULL_DEREFERENCE @@ -178,6 +190,8 @@ NullPointerExceptions.java, int NullPointerExceptions.preconditionCheckStateTest NullPointerExceptions.java, void NullPointerExceptions$$$Class$Name$With$Dollars.npeWithDollars(), 2, ANALYSIS_STOPS NullPointerExceptions.java, void NullPointerExceptions$$$Class$Name$With$Dollars.npeWithDollars(), 2, NULL_DEREFERENCE NullPointerExceptions.java, void NullPointerExceptions.badCheckShouldCauseNPE(), 1, NULL_DEREFERENCE +NullPointerExceptions.java, void NullPointerExceptions.cursorFromContentResolverNPE(String), 9, ANALYSIS_STOPS +NullPointerExceptions.java, void NullPointerExceptions.cursorFromContentResolverNPE(String), 9, CLASS_CAST_EXCEPTION NullPointerExceptions.java, void NullPointerExceptions.cursorFromContentResolverNPE(String), 9, NULL_DEREFERENCE NullPointerExceptions.java, void NullPointerExceptions.derefNull(), 2, ANALYSIS_STOPS NullPointerExceptions.java, void NullPointerExceptions.derefNull(), 2, NULL_DEREFERENCE