Dead code removal in Eclipse platform and PDE

1 minute read

Every large Java code base carries code nobody calls any more. For future maintenance it is important to remove such dead code: every unused class still has to be read by the next developer, still shows up in searches and refactorings, still compiles against APIs that keep changing, and still needs to be migrated when the platform moves on, for example to a new Java version or a new SWT API. Finding candidates is easy. Proving that a class is really dead is the hard part, because references hide in other repositories, in plugin.xml, in .e4xmi models and in reflective calls, and a text search cannot see any of that.

We now offer dead code removal as a fixed-scope service for Eclipse RCP and Java code bases. This post shows what it found in the Eclipse Platform, Platform UI and PDE repositories.

Example: Eclipse Platform, Platform UI and PDE

As a dry run we cleaned the internal API of three Eclipse repositories, eclipse.platform, eclipse.platform.ui and eclipse.pde, with the complete Eclipse SDK open in the workspace so that references from other projects count. The sweep removed 12,676 lines in 147 files: 126 classes, among them a complete About dialog package that was never wired to anything, plus the message keys and package exports that only served them. The workspace showed no additional warning or error afterwards, and a full build of the Eclipse SDK aggregator passed.

Bar chart of dead code lines removed per bundle of the Eclipse Platform, Platform UI and PDE

The safety net mattered as much as the deletions. Dozens of classes had no reference inside their own repository but were used from other Eclipse projects. Two classes are referenced only from another plug-in’s plugin.xml, through their nested classes; deleting them would compile and fail at runtime. A few e4 addons exist only through bundleclass:// URIs in .e4xmi files. All of them were kept, and public API was excluded from the start, because zero references in one workspace proves nothing for an exported package.

Interested?

Details and a contact form: Dead code removal.

Updated: