diff --git a/infer/src/java/jSourceFileInfo.mll b/infer/src/java/jSourceFileInfo.mll index 16f1146e6..9a7924966 100644 --- a/infer/src/java/jSourceFileInfo.mll +++ b/infer/src/java/jSourceFileInfo.mll @@ -372,30 +372,33 @@ and skip_comments action = parse (** We scan source file [file] and record location of each class declaration *) let collect_class_location (program:JClasspath.program) (file:SourceFile.t) = - let cin = In_channel.create (SourceFile.to_abs_path file) in - let stack = [] in - let record_location ~classname ~col ~line = - let loc : Location.t = { line; col; file } in - let cn : JBasics.class_name = JBasics.make_cn classname in - Logging.debug Capture Verbose "set_java_location %s with location %a@." - (JBasics.cn_name cn) Location.pp_file_pos loc; - JClasspath.set_java_location program cn loc in - try ( - class_scan { record_location; stack; } (from_channel cin) ; - In_channel.close cin ) - with - | Failure s -> - raise - (Failure - (Printf.sprintf "Error parsing source file %s\n%s" (SourceFile.to_abs_path file) s)) - | Missing_opening_bracket -> - raise - (Failure (Printf.sprintf "Missing opening bracket error while parsing source file %s\n" - (SourceFile.to_abs_path file))) - | Missing_opening_parenthesis -> - raise - (Failure - (Printf.sprintf "Missing opening parenthesis error while parsing source file %s\n" - (SourceFile.to_abs_path file))) - + let path = SourceFile.to_abs_path file in + if String.is_suffix path ~suffix:".java" then ( + let cin = In_channel.create path in + let stack = [] in + let record_location ~classname ~col ~line = + let loc : Location.t = { line; col; file } in + let cn : JBasics.class_name = JBasics.make_cn classname in + Logging.debug Capture Verbose "set_java_location %s with location %a@." + (JBasics.cn_name cn) Location.pp_file_pos loc; + JClasspath.set_java_location program cn loc in + try ( + class_scan { record_location; stack; } (from_channel cin) ; + In_channel.close cin ) + with + | Failure s -> + Logging.debug Capture Verbose "Error parsing source file %s\n%s" + (SourceFile.to_abs_path file) s; + In_channel.close cin + | Missing_opening_bracket -> + Logging.debug Capture Verbose + "Missing opening bracket error while parsing source file %s\n" + (SourceFile.to_abs_path file); + In_channel.close cin + | Missing_opening_parenthesis -> + Logging.debug Capture Verbose + "Missing opening parenthesis error while parsing source file %s\n" + (SourceFile.to_abs_path file); + In_channel.close cin + ) }