From 06dfadecb74cde468fd1cd099fbf5d9ac0be7659 Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Fri, 12 May 2017 08:59:11 -0700 Subject: [PATCH] [pmd] handle failure of decoding procedure ids as Java methods Summary: The code was pretty fragile, it's less fragile now. We should probably just delete that and start outputting proper class/package info directly in the report.json instead of reverse-engineering them. Fixes #640 Reviewed By: jeremydubreil Differential Revision: D4905973 fbshipit-source-id: 1590067 --- infer/lib/python/inferlib/issues.py | 28 +++++++++++-------- infer/tests/codetoanalyze/cpp/errors/Makefile | 3 +- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/infer/lib/python/inferlib/issues.py b/infer/lib/python/inferlib/issues.py index 07a81ea45..0285f2ffe 100644 --- a/infer/lib/python/inferlib/issues.py +++ b/infer/lib/python/inferlib/issues.py @@ -208,17 +208,23 @@ def _pmd_xml_of_issues(issues): root.attrib['version'] = '5.4.1' root.attrib['date'] = datetime.datetime.now().isoformat() for issue in issues: - fully_qualifed_method_name = re.search('(.*)\(.*', - issue[JSON_INDEX_PROCEDURE_ID]) - class_name = '' - package = '' - if fully_qualifed_method_name is not None: - # probably Java - info = fully_qualifed_method_name.groups()[0].split('.') - class_name = info[-2:-1][0] - method = info[-1] - package = '.'.join(info[0:-2]) - else: + successful_java = False + if issue[JSON_INDEX_FILENAME].endswith('.java'): + fully_qualified_method_name = re.search( + '(.*)\(.*', issue[JSON_INDEX_PROCEDURE_ID]) + if fully_qualified_method_name is not None: + # probably Java, let's try + try: + info = fully_qualified_method_name.groups()[0].split('.') + class_name = info[-2:-1][0] + method = info[-1] + package = '.'.join(info[0:-2]) + successful_java = True + except IndexError: + successful_java = False + if not successful_java: + class_name = '' + package = '' method = issue[JSON_INDEX_PROCEDURE] file_node = etree.Element('file') file_node.attrib['name'] = issue[JSON_INDEX_FILENAME] diff --git a/infer/tests/codetoanalyze/cpp/errors/Makefile b/infer/tests/codetoanalyze/cpp/errors/Makefile index 1ee25aa0a..71116f45e 100644 --- a/infer/tests/codetoanalyze/cpp/errors/Makefile +++ b/infer/tests/codetoanalyze/cpp/errors/Makefile @@ -10,7 +10,8 @@ TESTS_DIR = ../../.. ANALYZER = infer CLANG_OPTIONS = -x c++ -std=c++11 -isystem$(ROOT_DIR) -c -INFER_OPTIONS = --ml-buckets cpp --no-filtering --debug-exceptions --project-root $(TESTS_DIR) --no-failures-allowed +INFER_OPTIONS = --ml-buckets cpp --no-filtering --debug-exceptions --project-root $(TESTS_DIR) \ + --no-failures-allowed --pmd-xml INFERPRINT_OPTIONS = --issues-tests SOURCES = \