Friday, June 13, 2014

dead code in Jetty

During today's coding session of our Scout IT Day (ImmobilienScout24's flavor of the FedEx or ShipIt Day), I spent some time analyzing the Jetty project.
It's been a bit cumbersome, as Jetty provides a bunch of classes whose usage is configurable (e.g. the RewriteHandler), so I ended up manually analyzing (i.e. figuring out what the class does) many classes. In the end, only a few classes of the org.eclipse.jetty.util package seem to be dead - if one could say so about classes from a near-public library.

Setup

To analyze Jetty, I used a yet unreleased version, but the current 1.5 release only produces 4 more false positives. Here's the plugin configuration I used:

<plugin>
  <groupId>de.is24.mavenplugins</groupId>
  <artifactId>deadcode4j-maven-plugin</artifactId>
  <version>1.5</version>
  <configuration>
    <modulesToSkip>
      <modulesToSkip>jetty-runner</modulesToSkip>
      <modulesToSkip>examples</modulesToSkip>
      <modulesToSkip>tests/test-webapps</modulesToSkip>
    </modulesToSkip>
  </configuration>
</plugin
I excluded jetty-runner because it unpacks all of Jetty's dependencies and thus classes from e.g. the JSP-API are analyzed and partly recognized as dead. Not what we want to know.
The other two modules define tests and other classes that are not recognized by deadcode4j (and intentionally so).

Results

I ended up with ~150 presumably dead classes out of ~2.000 - but as mentioned before, most of them are simply optional classes that some users probably use. Only candidates that I struggle with are:

  • org.eclipse.jetty.start.Version: Parses a version string. Seems to me like an old "internal" class that is no longer used, hard to imagine that anyone outside of Jetty itself makes use of it.
  • org.eclipse.jetty.util.HostMap: Maps hosts & domains to anything, provides a method to retrieve all entries for a host or it's parent domains. While this has its merits, the fact that it defines its own method to distinguish it from a regular HashMap, one would assume some Jetty code would use it (like e.g. the org.eclipse.jetty.util.IPAddressMap).
  • org.eclipse.jetty.util.TreeTrie: Kind of Map, but with fuzzy getters. This seems so specific (and other flavors like e.g. ArrayTernaryTrie being used internally), it's hard to imagine usages outside of Jetty.
To remove this classes may be too rash (after all, those are public classes in a publicly accessible library), but it seems like they could easily be deprecated for now.
Good job, Jetty maintainers!

About deadcode4j

deadcode4j is a Maven plugin which finds dead code. To use it, go to the console, navigate to your Maven project, type
  mvn de.is24.mavenplugins:deadcode4j-maven-plugin:find ‑Dmaven.test.skip=true
and see what it finds.

Hop on over to GitHub to learn more, browse the code, or contribute.

Here you can read how it all started.