find_unreachable_code
Analyze Java projects to identify code unreachable from declared entry points like main methods and test methods. Use results to detect dead code while noting reflection and DI may be invisible.
Instructions
Find code unreachable from any entry point, project-wide.
USAGE: find_unreachable_code() OUTPUT: Members (types, methods, fields) that no entry point reaches, with visibility and location, plus the roots used.
Roots are public static void main(String[]) methods and detected test methods (JUnit 4/5, TestNG; disabled tests still count). Reachability follows calls, instantiations, field accesses, field initializers, and overrides (a call through an interface or superclass reaches every override). A type is reported only when neither it nor any of its members is reachable.
IMPORTANT: results mean "unreachable from declared entry points", not "safe to delete" - reflection, dependency injection, and serialization entry points are invisible to the graph.
Options:
includeTestRoots: count test methods as entry points (default true)
maxResults: cap the reported list (default 100)
Requires load_project to be called first.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| includeTestRoots | No | Treat test methods as entry points (default true) | |
| maxResults | No | Maximum entries to return (default 100) |