diff --git a/infer/src/harness/stacktrace.ml b/infer/src/harness/stacktrace.ml index 77b7a485f..4d401fa6d 100644 --- a/infer/src/harness/stacktrace.ml +++ b/infer/src/harness/stacktrace.ml @@ -60,10 +60,16 @@ let parse_stack_frame frame_str = if string_equal file_and_line "Native Method" then make_frame class_str method_str "Native Method" (-1) else begin - (* separate the filename and line number *) - ignore(Str.string_match file_and_line_regexp file_and_line 0); - let file_str = Str.matched_group 1 file_and_line in - let line_num = int_of_string (Str.matched_group 2 file_and_line) in + (* Separate the filename and line number. + note that a few methods might not have line number information, + for those, file_and_line includes only the filename. *) + let is_file_line = Str.string_match file_and_line_regexp file_and_line 0 in + let file_str = if is_file_line + then Str.matched_group 1 file_and_line + else file_and_line in + let line_num = if is_file_line + then int_of_string (Str.matched_group 2 file_and_line) + else -1 in make_frame class_str method_str file_str line_num end diff --git a/infer/src/unit/stacktraceTests.ml b/infer/src/unit/stacktraceTests.ml index 6ce2cd2fd..b56fa5747 100644 --- a/infer/src/unit/stacktraceTests.ml +++ b/infer/src/unit/stacktraceTests.ml @@ -69,5 +69,23 @@ let tests = assert_equal trace expected in "multi_frame_trace_test">::multi_frame_trace_test_ in + let missing_line_info_test = + let missing_line_info_test_s = + "Exception in thread \"main\" java.lang.NullPointerException\n" ^ + "\tat endtoend.java.checkers.crashcontext.MinimalCrashTest.main" ^ + "(MinimalCrashTest.java)" in + let trace = Stacktrace.of_string missing_line_info_test_s in + let expected = Stacktrace.make + "java.lang.NullPointerException" + [Stacktrace.make_frame + "endtoend.java.checkers.crashcontext.MinimalCrashTest" + "main" + "MinimalCrashTest.java" + (-1)] in + let missing_line_info_test_ _ = + assert_equal trace expected in + "missing_line_info_test">::missing_line_info_test_ in + "all_tests_suite">:::[empty_string_test; empty_trace_test; - one_frame_trace_test; multi_frame_trace_test] + one_frame_trace_test; multi_frame_trace_test; + missing_line_info_test]