> Graphify: shared context of codebase for agents and developers. Canonical: https://graphify.com/blog/find-java-callers-before-a-refactor · Full index: https://graphify.com/llms-full.txt

# Find Java callers before a refactor

*November 23, 2026 · Syed Fahad*

Before you change a busy Java method, list the callers, including tests and examples the diff will not show.

This walkthrough uses the Graphify CLI on a public checkout of [google/gson](https://github.com/google/gson) at commit `d9b5079` (21 November 2026). The same commands work in other Java repositories. The TypeScript and Python versions of this workflow are in [find every caller before a refactor in TypeScript](https://graphify.com/blog/find-typescript-callers-before-a-refactor) and [how to generate a call graph for a Python project](https://graphify.com/blog/how-to-generate-a-call-graph-for-a-python-project).

## How do I find every Java caller before a refactor?

Build a code graph of the repository with `graphify update .`, then run `graphify affected` on the method. If the name appears in more than one class, pick the node with path::symbol and run the query again.

```bash
uv tool install --python 3.12 graphifyy
git clone https://github.com/google/gson.git
cd gson
git checkout d9b5079
graphify update .
graphify affected "fromJson"
```

On this checkout the CLI read 301 files and finished in about 6 seconds. The graph had 5,614 nodes, 19,829 edges and 207 communities. Of those edges, 15,206 were EXTRACTED and 4,623 were INFERRED. The CLI's code pass wrote no AMBIGUOUS edges. Results vary by codebase.

`fromJson` is a fair test of the workflow because the name is both popular and overloaded. The bare query does not guess:

```text
graphify affected "fromJson"
Ambiguous: 'fromJson' matches 3 nodes in different files.
  gson/src/main/java/com/google/gson/Gson.java
  test-shrinker/src/main/java/com/example/Main.java
  gson/src/main/java/com/google/gson/TypeAdapter.java
Retry with path::symbol using one of the paths above
```

Scope it to the method you are actually changing:

```bash
graphify affected "gson/src/main/java/com/google/gson/Gson.java::.fromJson()"
```

The graph had 572 call edges into that `Gson.fromJson` method at this checkout. 571 of those were INFERRED, and one was EXTRACTED, a self-edge on the method itself. `graphify affected` walks those calls, plus other inbound relationships, at depth 2. The start of the output was:

```text
- .main() [calls] extras/src/main/java/com/google/gson/extras/examples/rawcollections/RawCollectionsExample.java:L51
- .testCollection() [calls] extras/src/test/java/com/google/gson/interceptors/InterceptorTest.java:L79
- .testCustomTypeAdapter() [calls] extras/src/test/java/com/google/gson/interceptors/InterceptorTest.java:L134
- .testExceptionsPropagated() [calls] extras/src/test/java/com/google/gson/interceptors/InterceptorTest.java:L58
- .testField() [calls] extras/src/test/java/com/google/gson/interceptors/InterceptorTest.java:L105
- .testList() [calls] extras/src/test/java/com/google/gson/interceptors/InterceptorTest.java:L71
```

That is the point of running this before a refactor: most of the people who will feel a signature change are in tests and examples, not in `Gson.java` itself.

## Why is grep a weak way to find Java callers?

Grep finds the method name, not the relationship. Overloads, methods of the same name on other classes, and calls through a wrapper all share that string, so the list is both noisy and incomplete.

A search for `fromJson` in this repository also hits `TypeAdapter.fromJson` and the shrinker example. Mixing those callers together is how a refactor gets merged with a test still calling the other method. The ambiguous prompt exists to stop that mix-up. The general version of this argument is in [code change blast radius](https://graphify.com/blog/code-change-blast-radius).

## What if the method name is used in several Java classes?

The CLI lists each matching node, with its file, and asks you to retry with path::symbol. That is expected. It is better than silently mixing the callers of two different methods.

If you really want both, run the scoped query once per node and keep the lists separate.

## Does a Java code graph include test callers?

Yes, if the tests are in the repository and the CLI can parse them. On the gson checkout, most of the inbound calls to Gson.fromJson were in tests and examples, which is what you want when you change a popular method.

571 of those 572 call edges were INFERRED, and the one EXTRACTED edge was a self-edge on the method. INFERRED means the CLI resolved the call by inference, not by reading a single unambiguous site in the syntax tree. Open the test, confirm it really calls `Gson.fromJson`, then decide whether your change needs to update it.

After you edit, run `graphify update .` again, or use `graphify hook install` so the graph rebuilds after commits, checkouts, merges and rewrites. The [install guide](https://graphify.com/blog/install-graphify) covers setup, and the hosted app is at [app.graphify.com](https://app.graphify.com).
