A Doclet for checking @Override annotations

It turns out that one of the blockers (possibly the blocker?) for supporting Java 1.6 in Android platform builds is the awkward incompatibility between Java 1.5 and Java 1.6 in the way @Override annotations are handled. This Doclet might help, it outputs each instance of an @Override annotation applied to an interface method implementation (permitted in Java 1.6 but illegal in 1.5).


Every class in every specified package is analyzed irrespective of the filtering imposed by the doclet parametes. A line starting "ERROR" is output to stdout for every instance discovered. It may occur(?) that javadoc doesn't have enough information to determine, one way or another, whether a method is a genuine override or simply an implementation. In this case a "WARNING" is output.

A debug flag ("-debug") can be specified when executing this doclet via javadoc. This will output every package, class, method and annotation considered.



The OverrideCheck class can be compiled under Java 1.5 or Java 1.6. It has a dependency on tools.jar (typically found in $JDK_HOME/lib). Compile like so:

javac -cp <path-to-tools.jar> -d <class-output-dir> <path-to-src-file>

Output consists of a single the class file OverrideCheck.class.

Adding the option -target 1.5 will allow the doclet to be run under Java 1.5.


Invoke as per any Doclet:

javadoc -docletpath <path to doclet classes> -doclet OverrideCheck \
  -classpath <path to binary source dependencies> \
  -sourcepath <path to source code> \
  <list of packages to be analyzed>

(see javadoc tool documentation)


9th November 2009 -
Added build instructions.

1st October 2009 -
Fails on errors.
Uses all included classes instead of walking packages.
This change now mandates use of the javadoc -private switch to trap all classes.