Skip to content

fix(java): keep _name/name and case-only member twins apart in node ids - #5152

Closed
rohit-jsfreaky wants to merge 1 commit into
Graphify-Labs:v8from
rohit-jsfreaky:fix/java-underscore-ids
Closed

rohit-jsfreaky wants to merge 1 commit into
Graphify-Labs:v8from
rohit-jsfreaky:fix/java-underscore-ids

Conversation

@rohit-jsfreaky

Copy link
Copy Markdown
Contributor

Closes #5151

What does this PR do?

Java methods and constructors whose names differ only by a leading _ or by case in one class, interface, record or enum body now get separate node ids, the same way as Python and C# (#3302, #4415) and Solidity (#5058).

A small helper _java_member_nid groups the members of one body by the id they would get, then runs each group through the existing _underscore_salted_nid: the one public name keeps its id and the others get a salted id. Nothing outside a colliding group changes.

_AST_CACHE_SCHEMA 43 -> 44 (Java output changes).

Diff: engine.py +44, cache.py +1/-1, 4 tests.

Numbers

The answer key is a separate tree-sitter-java scan that counts declarations per class.

repo colliding groups methods with no node: v8 -> this PR calls on a wrong-named method on v8
jsoup 1 1 -> 0 3
commons-lang 5 5 -> 0 5
jackson-core 35 35 -> 0 223
jackson-databind 101 101 -> 0 363
guava 18 18 -> 0 18
spring-framework 5 6 -> 0 7
  • Ids that changed outside the colliding groups: 0 in all 6 repos. Inside them, 34 v8 ids changed: pairs where neither name starts with _ (HashCode()/hashCode(), getId/getID), so both names are salted, as in Python and C#.
  • 10 edges away from the pairs changed, all for the better:
    • jackson-core: WriterBasedJsonGenerator._writeString(name) went to a method in a test class on v8. It now goes to the right method in the same class.
    • jackson-databind: three prop.depositSchemaProperty() calls fell back to the abstract PropertyWriter. They now bind BeanPropertyWriter's own override.
    • guava: two new Range<>(...) calls now target the constructor node, as v8 already does for a class with no collision.
    • spring-framework: 6 builder-chain calls (.withClassPathLocations(...).withFilePrefixes(...)) now resolve through the builder's return type.

Limitations

  • Enum constants that clash with a method name (EXECUTOR / executor(): 4 in guava, 2 in spring) are not covered, to keep this small.
  • Overloads (foo(int) / foo(String)) still share one node. That's an older, separate limitation.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Tests or CI
  • Refactor
  • Security fix

Verification & Invariants

Invariant: every Java method and constructor declaration gets its own node, and a call is credited to the member it is written in. Ids outside a colliding group are unchanged. Persisted state: the AST cache is bumped, so cached Java extractions re-run.

  • Read the CONTRIBUTING.md guide.
  • Reproduced the issue and identified the invariant.
  • Made the smallest fix necessary.
  • Added a regression test (if bug fix) or isolated boundary test.
  • Kept the PR description synchronized with the final implementation.
  • Documented any limitations / unsupported cases explicitly.

How was this tested?

uv run --frozen pytest tests/test_java_underscore_ids.py -q   # 4 passed; on v8: 4 failed (`._bar()` node missing)
PYTHONPATH="$PWD" uv run --frozen pytest tests -q             # 11031 passed, 122 skipped, 1 xfailed (v8: 11027 passed)
uv run --frozen ruff check .                                  # clean
pyright graphify/extractors/engine.py graphify/cache.py       # same errors as v8, none new

Tests cover _bar/bar, case-only twins, enum and interface bodies, and cross-file member calls (obj._bar() vs obj.bar()).

Graphify-specific checklist

  • I updated generated skill artifacts (uv run python -m tools.skillgen --bless) when changing their source fragments.
  • I confirmed that AST/structural extraction remains deterministic (no ambient state dependencies like ENV variables).
  • I reviewed changes for security implications (no unsafe interpolation into shell/Python).
  • I confirmed no API keys or local-only graph data are included.
  • (If applicable) I disclosed AI authorship in my commit messages.

…de ids

make_id strips a leading `_` and folds case, so in one Java class body
`_testFoo()` / `testFoo()`, `getId()` / `getID()` and a constructor
`HashCode()` / method `hashCode()` minted ONE id. add_node kept the first
declaration and dropped the second: the method vanished, the calls it
makes were credited to its twin, and calls to it landed on the twin (or,
when the survivor's name no longer matched, fell back to a supertype's
method or to another file's method).

Apply the Python/C#/Solidity rule (Graphify-Labs#3302, Graphify-Labs#4415, Graphify-Labs#5058): group the
methods and constructors of each class/interface/record/enum body by the
id they would get and run each through `_underscore_salted_nid`. The one
public name keeps the plain id, every other spelling is salted. Members
that collide with nothing keep their ids; overloads share one name, so
they are not a collision.

Measured on jsoup, commons-lang, jackson-core, jackson-databind and
guava: 160 colliding groups (131 of them `_x`/`x`), 160 methods that had
no node on v8 now do, and 612 call edges that v8 credited to a
differently-named method now hit the right one. No id changed outside a
colliding group, and no edge away from those groups changed.

Bump _AST_CACHE_SCHEMA to 44 so cached Java extractions re-run.

Co-Authored-By: Claude <[email protected]>
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @rohit-jsfreaky. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic.

@rohit-jsfreaky

Copy link
Copy Markdown
Contributor Author

Note: my open #5052 also bumps _AST_CACHE_SCHEMA 43 -> 44 (Python output). Whichever lands second takes 45; I'll rebase it.

@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Nov 11, 2026

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graphify reviewed this change.

No issues found by static checks — no coupling regressions or blocking issues in the code graph. That is not the same as safe to merge: see what was not checked.

Not checked: tests were not run; formal verification proved 0 of 1 changed function(s) (1 not verified).

Formal verification. PR-changed functions: 0/1 verified (0 proven, 0 may-equivalent, 0 distinguished) · 1 not verified (1 unsupported).

Not verified on this run: \_extract\_generic (unsupported).


Graphify review — findings

Bumps _AST_CACHE_SCHEMA to 43 so cached Python and C++ extractions re-run. The new extraction behaviour: a dotted Python subscript annotation (mod.MyBox[Foo]) walks its value once as the type, so the false generic_arg reference no longer displaces the real parameter_type/return_type edge. C++ gains forward-declaration folding into a unique exactly-qualified definition and member-declaration folding into its out-of-line definition. Member receivers now resolve through scoped type aliases and inherited fields/methods, and calls in #if-guarded initializers are recovered. Ambiguous, virtual, diamond and dependent cases stay unresolved. The diff is truncated, so the engine-side changes behind the other listed symbols aren't visible here.

No blocking issues surfaced. 1 lower-confidence candidate did not survive cross-model review.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 4530 functions depend on the 534 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: extract() — 1207 callers, 78 callees
  • worse: walk() — 1 callers, 90 callees

Verification — 4530 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 2958 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

98 of 555 test file(s) selected (18%) via static blast radius.

  • tests/test_4992_ts_import_types.py — impact
  • tests/test_astro_extraction.py — impact
  • tests/test_binary_media_words.py — impact
  • tests/test_build.py — impact
  • tests/test_cache.py — impact
  • tests/test_cache_long_paths.py — impact
  • tests/test_cache_stale_import_target.py — impact
  • tests/test_cache_windows_case_4925.py — impact
  • tests/test_charmap_encoding.py — impact
  • tests/test_chunking.py — impact
  • tests/test_cjs_module_extension.py — impact
  • tests/test_code_only_scope_4923.py — impact
  • tests/test_cpp_alias_member_resolution.py — impact
  • tests/test_cpp_conditional_initializers.py — impact
  • tests/test_cpp_inherited_member_resolution.py — impact
  • tests/test_cpp_nested_and_cli.py — impact
  • tests/test_cpp_template_members.py — impact
  • tests/test_csharp_extension_calls.py — impact
  • tests/test_csharp_extension_metadata.py — impact
  • tests/test_csharp_extension_resolution.py — impact
  • tests/test_csharp_partial_classes.py — impact
  • tests/test_definition_file_portability.py — impact
  • tests/test_detect.py — impact
  • tests/test_dotnet.py — impact
  • tests/test_ejs_extractor.py — impact
  • tests/test_ext_tagged_id_clash.py — impact
  • tests/test_extract.py — impact
  • tests/test_extract_cache_location.py — impact
  • tests/test_extract_cli.py — impact
  • tests/test_extract_php_closures.py — impact
  • tests/test_grammar_cache_key.py — impact
  • tests/test_hook_content_freshness.py — impact
  • tests/test_ignore_file_encoding.py — impact
  • tests/test_import_extension_resolution.py — impact
  • tests/test_incremental_mtime_collision.py — impact
  • tests/test_indirect_call_block_scoped_shadow.py — impact
  • tests/test_indirect_dispatch.py — impact
  • tests/test_indirect_dispatch_assign_return.py — impact
  • tests/test_indirect_dispatch_getattr.py — impact
  • tests/test_java_member_calls.py — impact
  • tests/test_java_underscore_ids.py — impact, changed-test
  • tests/test_js_exported_scalar_bindings.py — impact
  • tests/test_js_member_collisions.py — impact
  • tests/test_language_override_lifecycle.py — impact
  • tests/test_language_overrides.py — impact
  • tests/test_languages.py — impact
  • tests/test_linked_worktree_reconcile.py — impact
  • tests/test_llm_backends.py — impact
  • tests/test_manifest_ingest.py — impact
  • tests/test_msbuild_dir_evidence.py — impact
  • … and 48 more

Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.

Docs that may be stale (advisory)

…and 10 more.

Formal verification

Could not verify: Could not verify \_extract\_generic.

The verifier did not have enough to check \_extract\_generic, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: no capturable inputs from the test suite; property tier: parameter `config` is annotated `LanguageConfig` — outside the synthesizable primitive/collection set

· 2 more finding(s) on lines outside this diff (see the check run).

@safishamsi

Copy link
Copy Markdown
Member

Landed on v8 as bd720f1 via authorship-preserving cherry-pick, released in graphify 0.9.107. Thanks @rohit-jsfreaky.

@safishamsi safishamsi closed this Nov 12, 2026
This was referenced Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor Pull request from a returning community contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Java: _bar() and bar() (or getId/getID) share one node id, so one method vanishes and its calls go to the other

2 participants