Skip to content

--emit neo4j: all JField nodes share id <fqn>#field#null, collapsing every field of a class into one node #156

Description

@rahlk

Summary

--emit neo4j assigns every :JField node the id <ownerFqn>#field#null, so all fields of a class collapse into a single :JField node (the unique-constraint MERGE keeps only the last). Field data is almost entirely lost.

Environment

  • codeanalyzer-java 2.4.0

Impact

Measured on the daytrader8 sample (level 2): all 122 :JField nodes in the database have an id ending in #field#null, and every one has name = null. A class with 17 fields (e.g. XMLObject, RunStatsDataBean) ends up with a single :JField node. Any consumer reading fields from the graph (e.g. the CLDK SDK's read-only Java backend) gets one field per class instead of all of them.

MATCH (f:JField) WHERE f.id ENDS WITH '#field#null' RETURN count(f);   // 122  (== total JField count)
MATCH (:JType {id:'...XMLObject'})-[:J_HAS_FIELD]->(f:JField) RETURN f.id;
//  -> '...XMLObject#field#null'   (a single node; ref analysis.json has 17 field_declarations)

Root cause

neo4j/GraphProjector.java, projectField:

String id = ownerFqn + "#field#" + f.getName();

A Java field declaration is keyed by its variables list, not a single name — Field.getName() is null here (the model has no scalar field name; the projected node even sets "name", f.getName() ⇒ null). So every field's id is <fqn>#field#null, and the j_field_id uniqueness constraint collapses them on MERGE.

Suggested fix

Key the field id by something unique per declaration — e.g. the first variable name, the joined variables, or a positional index:

String key = (f.getVariables() != null && !f.getVariables().isEmpty())
        ? String.join("+", f.getVariables())
        : String.valueOf(index);
String id = ownerFqn + "#field#" + key;

(and project the real field name/variables so they round-trip).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions