#74 Import req'd by javadoc reported unused

Oliver Burn
Patrick Tullmann

Some import statements in a .java source file may not
be necessary for compilation, but are required for
javadoc to generate pretty hyperlinks. Basically, if a
class in a different package is referenced only in an
@see or @link in a comment, javadoc requires an import


Here's an example:

import java.util.List;
import java.util.ArrayList;

* Example of an import that is needed for
* javadoc, but not javac.
* Remove the 'import java.util.ArrayList'
* and javadoc will complain.
public class Importdoc

* Munge a List. Optimized for the case
* where l is an
* {@link ArrayList}.

* @param l the list to munge

public void mungeList(List l)


<< < 1 2 (Page 2 of 2)
  • I am just a user of checkstyle. You may stone me, but I think checkstyle is right.
    The problem is your IDE:

    However for convenience checkstyle should add a trigger to allow to accept such situation.

  • Johan Walles
    Johan Walles

    How to treat imports required by javadocs only is a matter of taste, and it would be very nice if the current UnusedImports check could get an option for how to handle such imports.

    Right now we have this check turned off since we get too many false positives. Being able to configure it to accept javadoc as a reason for an import would enable us to turn it on again.

  • Eric

    I'll add a "me too" to this one.

    Without this option, checkstyle forces the user to to use the fully qualified class names in cases where your javadoc is referencing classes that your code is not. This is just plain ugly.

  • Stevo Slavic
    Stevo Slavic

    Following javadoc FAQ explains that referenced class "must be referenced by a declaration or any kind of import statement": http://java.sun.com/j2se/javadoc/faq/index.html#missinglinks

    IMO proper solution would be to fix "Unused imports" check so +1 for that. Current workaround is to reference class using full class path and not just by name.

  • Sergei Ivanov
    Sergei Ivanov

    Please implement a fix for this issue, it's been bugging us for years.

  • Oliver Burn
    Oliver Burn

    Fixed in changeset 10b232dfd037

  • Thank you, however, this doesn't cover nested classes. For example:

    import Foo;
     *  {@link Foo.Bar}

    would be reported, while shouldn't.

    Last edit: Dzmitry Lazerka 2014-06-10
  • Same thing about fields:

    import Foo;
     * {@link Foo#BAR}
<< < 1 2 (Page 2 of 2)