Skip to content

fix(java): load an application whose types share a qualified name, and refuse only the queries keyed by it (#420) - #451

Open
sinha108 wants to merge 3 commits into
mainfrom
fix/420-duplicate-fqns
Open

sinha108 wants to merge 3 commits into
mainfrom
fix/420-duplicate-fqns

Conversation

@sinha108

@sinha108 sinha108 commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #420.

An application whose types share a qualified name (vendored copies of one library across services) could not be loaded. JCodeanalyzer raised duplicate_type_name from _index() at construction, and JNeo4jBackend raised it lazily on first use. This PR follows the issue's proposal: load always, and refuse only the queries a contested name makes ambiguous.

Loading

  • One index for both backends. index_types, in analysis/java/backend.py, is called by both backends, so they behave the same and refuse at the same point.
  • Every declaration is kept. NameIndex maps a name to its declarations and their files. Callables stay keyed by their can:// id, which is unique per copy, and each callable's file is indexed by that id, never by its owner's name, which the copies share.
  • One warning. If any name is contested, the index logs one warning with their count and an example.

Types

  • Keyed by a contested name: get_class, get_java_file and the like raise CodeanalyzerExecutionException, naming the competing files. The message says the name is declared in more than one file; it no longer blames the analyzer.
  • Filtered, name-keyed answers (get_all_sub_classes, get_all_entry_point_classes, the per-kind accessors) refuse only when a contested name would be one of their keys.
  • Answers that carry each entry's file (get_entrypoint_classes, get_all_comments over Neo4j) list every copy.
  • The unfiltered get_all_classes() still refuses, since every name is one of its keys.
  • New get_class_declarations(name), on the backends and the facade: every declaration of a name, by file. Empty when nothing declares it; never raises.

Callables

  • Everything uncontested answers as before: locate, resolve_callable, get_source, the CRUD and taint queries. locate also works in either copy's file.
  • A key two copies spell (<fqn>.<signature>) names neither. Each copy answers to <fqn>.<signature>@<file>:
    • resolve_callable raises AmbiguousName, listing that spelling for each copy. Either the spelling or in_module= resolves it.
    • A lookup keyed by the bare key, such as get_source, raises with both files.
    • get_callables_overview() lists each copy under its @<file> key.
  • The call graph keeps copies apart. A contested key's copies are separate nodes keyed <fqn>.<signature>@<file>, each with its own edges. Before, they were merged into one node silently. Uncontested node keys don't change.

Call-graph queries

  • get_all_callers / get_all_callees on a contested (class, signature) refuse, naming both files, instead of answering {}. "<signature>@<file>" asks about one copy.
  • get_class_call_graph on a contested class refuses instead of merging both copies' edges.
  • The symbol-table call graph resolves an implicit receiver against the owner's own copy and does not follow a receiver or supertype name declared in more than one file, since the call site does not say which copy it means. Questions about uncontested classes answer as they did without the copy. Its nodes use the addressing keys.

Other whole-application answers

  • get_variables and JavaAnalysis.get_test_methods are keyed per callable, so they no longer refuse; each copy of a contested key is <key>@<file>.
  • get_all_entry_point_methods refuses only when a contested class declares an entry point.
  • get_all_methods_in_application, get_methods and get_class_hierarchy are keyed by every class name, so like get_all_classes() they refuse.

Existing public signatures don't change (get_class_declarations is the one addition), and index[name] = value and del index[name] still work for code that writes into _types.

Sequencing. As the issue asks, this lands with or behind codellm-devkit/codeanalyzer-java#279 (for #269). That PR binds each caller to its own copy and reports duplicates, so loading these analyses no longer means answering with wrong-copy edges.

Tests, each over both backends unless noted, on daytrader8 plus a vendored copy of one unit:

  • uncontested locate and resolve_callable answer, and locate works in the copy's file;
  • the contested key is an ambiguity, each @<file> spelling and in_module= resolve it, get_source refuses the bare key, and the overview lists both copies;
  • the call graph (over a4, which has call edges) has each copy's nodes and edges: 247 edges become 269, where before they stayed 247;
  • filtered answers refuse only when a contested name is in them, and file-carrying lists include both copies;
  • the call-graph queries and the symbol-table call graph, as above (over a4), and the whole-application answers;
  • get_class_declarations, on both backends and the facade, and get_test_methods through the facade (the in-memory backend);
  • one warning per index;
  • NameIndex assignment and deletion, as a unit test.

Full suite: 2,055 passed. The only failure is test_c_modules_are_gone. In my checkout a stale, git-ignored cldk/analysis/c/ directory (caches only) imports as a namespace package; it is unrelated to this change.

…420)

- A callable's file is indexed by its id, not its owner's name, so locate,
  resolve_callable and the queries built on them work for every
  uncontested callable, and for positions in either copy's file.
- A key two copies spell refuses as a lookup and is an ambiguity to
  resolve_callable; each copy answers to "<key>@<file>", and the call
  graph and get_callables_overview use that spelling, so copies are no
  longer merged into one node.
- Filtered, name-keyed answers refuse only when a contested name is in
  them; file-carrying lists include every copy; get_all_classes still
  refuses.
- New get_class_declarations(name): every declaration, by file.
…name (#420)

- get_all_callers/get_all_callees refuse a contested (class, signature),
  naming both files, instead of answering {}; "<signature>@<file>" asks
  about one copy. get_class_call_graph refuses a contested class instead
  of merging its copies' edges.
- The symbol-table call graph resolves an implicit receiver against the
  owner's own copy and does not follow a contested receiver or supertype,
  so uncontested questions answer as before; its nodes use the
  addressing keys.
- get_variables and get_test_methods key each callable, so they no longer
  refuse; get_all_entry_point_methods refuses only when a contested class
  declares an entry point.
@sinha108
sinha108 marked this pull request as ready for review November 23, 2026 15:35
@sinha108
sinha108 requested a review from rahlk November 23, 2026 15:45

This branch has not been deployed

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

Labels

fix Bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Duplicate FQNs make a Java application unloadable, not just its ambiguous queries unanswerable

1 participant