#74 Import req'd by javadoc reported unused

release_4.1
closed
Oliver Burn
None
4
2014-08-27
2002-12-11
Patrick Tullmann
No

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
statement.

See:
http://java.sun.com/j2se/1.3/docs/tooldocs/solaris/javadoc.html#howaclassmustbereferenced

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)
{
}
}

Discussion

<< < 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:
    https://bugs.eclipse.org/bugs/show_bug.cgi?id=128661

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

     
  • Johan Walles
    Johan Walles
    2010-03-24

    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
    Eric
    2011-01-19

    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
    2011-03-30

    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
    2011-07-11

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

     
  • Oliver Burn
    Oliver Burn
    2011-07-12

    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)