Skip to content

[Feature]: Java: a call through an interface-typed field stops at the interface method (no dispatches_to to implementers) #5319

Open

Description

@livingforelvis

Problem

For C#, Swift and Go, interface_dispatch links an interface method to the methods of
its implementers (dispatches_to, #3003, #4934). Java has the same shape, but no pass
is registered for .java, so a call through an interface-typed field ends at the
interface method and a directed walk cannot reach the class that runs.

Minimal repro (graphify 0.9.112, v8 at 340268a)

// Worker.java
public interface Worker {
    void run();
}

// EmailWorker.java
public class EmailWorker implements Worker {
    public void run() {
        send();
    }

    private void send() {
    }
}

// Job.java
public class Job {
    private final Worker worker;

    public Job(Worker worker) {
        this.worker = worker;
    }

    public void execute() {
        this.worker.run();
    }
}

$ GRAPHIFY_BACKEND=none graphify extract <dir> --code-only --out <out>
$ graphify path "Job.execute" "EmailWorker.run" --graph <out>/graphify-out/graph.json
No directed path found between 'Job.execute' and 'EmailWorker.run'. Re-run with --undirected to search ignoring edge direction.

Observed: Job.execute() --calls--> Worker.run() and no dispatches_to edge in the graph
(11 nodes, 13 edges). Nothing links Worker.run() to EmailWorker.run().

Expected: Worker.run() --dispatches_to--> EmailWorker.run(), as for C#/Swift/Go.

Proposal

Register a thin Java wrapper over resolve_interface_dispatch with suffixes=(".java",),
like swift_dispatch.py. The Java extractor already emits implements (classes, enums,
records, generic and nested interfaces) and the interface's method edges, so no extractor
change and no AST cache schema bump is needed (as for Swift, #4035). Same rules as the other
languages: additive INFERRED edges at 0.85 / 0.75 / 0.65 by implementer count, both ends
declared in .java.

I have a branch with this and tests (single implementer, two and three implementers,
overloads paired by signature (now that each Java overload has its own node, #5251), constructor, default method, enum/record/generic implementers, same simple name
in two packages, Kotlin and C# name collisions) and can open the PR.

Known limits I found (would be documented and pinned by tests)

  • extends (abstract class / subclass override) is not read: a base method may be the real target.
  • Interface hierarchies (interface Task extends Worker) are not walked, same as C#.
  • A default method nobody overrides gets no edge: the call really lands on the default body.
  • implements a.Worker written fully qualified with no import binds to a sourceless stub, so it gets no edge (fails closed); the imported form links.

Out of scope / follow-up

  • Abstract-class override dispatch (needs inherits); happy to open a separate issue.
  • Kotlin / Scala.

Activity

  1. github-actions commented on Nov 18, 2026

    @github-actions

    Thanks for opening this issue, @livingforelvis. 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.

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