Skip to content

Parsing Java for_statements Bug in ccg.py #6

@watreyoung

Description

@watreyoung

When I tried to reproduce the context database construction, this error just occurs:

./repositories/Aelysium-Group_rusty-connector/plugin/core/src/main/java/group/aelysium/rustyconnector/core/lib/crypt/Token.java:   4%|| 14/356 [00:00<00:03, 99.51it/s]
Traceback (most recent call last):
  File "GraphCoder/build_graph_database.py", line 91, in <module>
    graph_db_builder.build_slicing_graph_database(repo)
  File "GraphCoder/build_graph_database.py", line 55, in build_slicing_graph_database
    ccg = create_graph(src_lines, repo_name)
  File "GraphCoder/utils/ccg.py", line 749, in create_graph
    java_control_dependence_graph(child, ccg, code_lines, None)
  File "GraphCoder/utils/ccg.py", line 543, in java_control_dependence_graph
    java_control_dependence_graph(child, CCG, src_lines, parent)
  File "GraphCoder/utils/ccg.py", line 543, in java_control_dependence_graph
    java_control_dependence_graph(child, CCG, src_lines, parent)
  File "GraphCoder/utils/ccg.py", line 543, in java_control_dependence_graph
    java_control_dependence_graph(child, CCG, src_lines, parent)
  [Previous line repeated 1 more time]
  File "GraphCoder/utils/ccg.py", line 430, in java_control_dependence_graph
    end_row = root_node.child_by_field_name('right').end_point[0]
AttributeError: 'NoneType' object has no attribute 'end_point'

I checked the Line 430 in ccg.py and Line 678-702 ingrammar.js in tree-sitter-java. I found that there is no 'right' child in for_statement:

    for_statement: $ => seq(
      'for', '(',
      choice(
        field('init', $.local_variable_declaration),
        seq(
          commaSep(field('init', $.expression)),
          ';',
        ),
      ),
      field('condition', optional($.expression)), ';',
      commaSep(field('update', $.expression)), ')',
      field('body', $.statement),
    ),

    enhanced_for_statement: $ => seq(
      'for',
      '(',
      optional($.modifiers),
      field('type', $._unannotated_type),
      $._variable_declarator_id,
      ':',
      field('value', $.expression),
      ')',
      field('body', $.statement),
    ),

So I changed Line 430 in ccg.py:

            end_row = root_node.child_by_field_name('condition').end_point[0]

It makes sense, but I'm not sure whether it is right or not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions