Skip to content

Java: methods and calls inside anonymous class bodies are dropped #4139

Description

@rajatnagda45

Version / commit

v0.9.77 (v8 @ 5c7b847)

Environment

macOS, Python 3.13, clean checkout of v8.

What happens

A Java anonymous class (new Runnable() { … }) contributes nothing to the graph: its methods are not nodes, and every call made inside them is dropped. Anonymous listeners/callbacks are routine in Java, so a large slice of the call graph silently disappears. Kotlin's equivalent (object : Foo { … }, #2347) is already handled — Java is the gap.

Minimal reproduction

// App.java
class App {
    void setup() {
        Runnable r = new Runnable() {
            public void run() { helper(); }
        };
    }
    void helper() {}
}
from graphify.extract import extract_java
r = extract_java("App.java")
print([n["label"] for n in r["nodes"]])
# -> ['App.java', 'App', '.setup()', '.helper()']   # run() missing
print([(e["source"], e["target"]) for e in r["edges"] if e["relation"] == "calls"])
# -> []   # run() -> helper() lost

Expected vs actual

  • Expected: a node for the anonymous class's run() with a calls edge to helper() (as Kotlin's object : Foo already produces).
  • Actual: the anonymous body and its calls are absent.

Root cause

The body hangs off an object_creation_expression as a class_body. That node is not in class_types and the function branch never recurses into bodies, so the members are never walked — the exact shape Kotlin #2347 fixed for object_literal.

A clean checkout of v8 reproduces it. Fix PR to follow.

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