[Bug]: Java: _bar() and bar() (or getId/getID) share one node id, so one method vanishes and its calls go to the other
Pre-flight checks
- [x] I have checked the Troubleshooting section in the README
What happened?
In Java, two members of one class whose names differ only by a leading _ (_bar() / bar()), or only by case (getId() / getID(), HashCode() constructor / hashCode()), get one node id. One method disappears from the graph, and its calls are credited to the other method.
This is the same bug fixed for Solidity in #5058. Python and C# already keep such twins apart (#3302, #4415): the one public name keeps its id and the others get a salted id (_underscore_salted_nid).
How often it happens on real repos (answer key: a separate tree-sitter-java scan counting declarations per class):
| repo | colliding groups | methods with no node on v8 | calls on the wrong method on v8 |
|---|---|---|---|
| jsoup | 1 | 1 | 3 |
| commons-lang | 5 | 5 | 5 |
| jackson-core | 35 | 35 | 223 |
| jackson-databind | 101 | 101 | 363 |
| guava | 18 | 18 | 18 |
| spring-framework | 5 | 6 | 7 |
Jackson uses the _name style for internal helpers, so it is hit hardest.
Steps to reproduce
// Foo.java
class Foo {
void bar() { helper(); }
private void _bar() { other(); }
void helper() {}
void other() {}
void caller() { _bar(); bar(); }
}
Run graphify update . (or extract([Path("Foo.java")])) and list the method nodes and calls edges.
Error output or graph output
methods: ['.bar()', '.caller()', '.helper()', '.other()'] # no ._bar()
calls: ['.bar() -> .helper()', '.bar() -> .other()', '.caller() -> .bar()']
Expected:
methods: ['._bar()', '.bar()', '.caller()', '.helper()', '.other()']
calls: ['._bar() -> .other()', '.bar() -> .helper()', '.caller() -> ._bar()', '.caller() -> .bar()']
Graphify version
0.9.106 (v8 at 35d1d203)
Operating System
Windows (also seen on Linux)
Python Version
3.12
Installation Method
uv tool install (recommended)
Thanks for opening this issue, @rohit-jsfreaky. A maintainer will take a look soon.
If you would like to discuss it in real time, come say hi on our Discord server. For longer-form questions and ideas there is also GitHub Discussions.
To help us triage, please make sure the report includes what you expected, what actually happened, and the steps (and a small sample) to reproduce it.
Fixed by #5152 (bd720f1f), released in graphify 0.9.107. Thanks @rohit-jsfreaky.