From ecfb00e0684a01da3cd9c4c7ff5e6b82df4ed9e8 Mon Sep 17 00:00:00 2001 From: Jeremy Dubreil Date: Fri, 10 Feb 2017 08:42:45 -0800 Subject: [PATCH] [infer][java] Always consider the close() method to be potentially closing a resource Summary: It seems that the `close()` method that should normally be called on an object `obj` of type `java.io.Closeable` is sometimes called on `obj` of type `java.lang.Object`. It did not fully understand in which case this happens but it could be coming from a bug in Sawja since the type of `obj` in the bytecode is correct, but the Sawja reciever expression given to the Java frontend has the type `java.lang.Object`. In any case, it does not hurt to always consider that `obj.close()` will replace the `FILE` attribute on `obj` by a `MEM` attribute. Reviewed By: sblackshear Differential Revision: D4540627 fbshipit-source-id: 71f9c95 --- infer/src/java/jTrans.ml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/infer/src/java/jTrans.ml b/infer/src/java/jTrans.ml index 7944dbc68..299a575c0 100644 --- a/infer/src/java/jTrans.ml +++ b/infer/src/java/jTrans.ml @@ -601,8 +601,7 @@ let method_invocation call_instrs @ [set_file_attr] (* remove file attribute when calling the close method of a subtype of Closeable *) - | (_, typ) as exp :: [] - when Procname.java_is_close callee_procname && JTransType.is_closeable program tenv typ -> + | exp :: [] when Procname.java_is_close callee_procname -> let set_mem_attr = let set_builtin = Exp.Const (Const.Cfun BuiltinDecl.__set_mem_attribute) in Sil.Call (None, set_builtin, [exp], loc, CallFlags.default) in