Bug 92821 - [javadoc] Organize Imports - M6 - incorrectly retains import when only referered to in javadoc
Summary: [javadoc] Organize Imports - M6 - incorrectly retains import when only refere...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 3.1 M7   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 100126 149752 266979 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-04-26 15:29 EDT by Geoff Longman CLA
Modified: 2011-08-03 04:26 EDT (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Geoff Longman CLA 2005-04-26 15:29:16 EDT
Just tried out M6 for the first time.

Given: I have a src file with an import that is not used by any source but is
referred to in javadoc comment.

Try: Organize Imports

Expected: that the unused import would be removed

What Really Happens: The import is not removed. I must use the "remove import"
quick fix (or delete the javadoc reference and organize again).
Comment 1 CLA 2005-04-26 17:50:08 EDT
To recreate, make the following class Foo.java as follows:

public class Foo {
    /**
     * @throws IOException
     */
    public void bar() {
        
    }
}

If you create this class then do an "Organise Imports" on it in the Java IDE 
then the following import will be inserted in the class file:

import java.io.IOException;

The Eclipse IDE will then complain that "The import java.io.IOException is 
never used".  You can try to do an "Organise Imports" again, but the error 
remains.

Deleting the "@throws IOException" javadoc clears the error.

PB

Comment 2 Dirk Baeumer CLA 2005-04-26 18:30:14 EDT
Importing the exception is correct when you have "Process Javadoc" enabled on
the compiler preference page since the Javadoc tool needs to have that import to
correctly generated Javadoc.

However there seems to be a problem that the compiler flags the import as unused
although it is used inside Javadoc.
Comment 3 Geoff Longman CLA 2005-04-26 21:11:36 EDT
I would submit that this statement:

"However there seems to be a problem that the compiler flags the import as unused
although it is used inside Javadoc."

ibhs completely backwards. An import is unused if it is not referenced in the
*code* not the javadoc. Javadoc is useful text but last time I checked it is not
part of the executable for my class. Isn't that what Annotations in JDK 1.5 are for?
Comment 4 Frederic Fusier CLA 2005-04-28 05:59:42 EDT
Side effect of build optimization.
Doc comment support was invalidate while building if no specific javadoc tags
options (invalid or missing) were set.
Need to add unused import also as in this case it's really important to look
inside javadoc to find used references...
Comment 5 Frederic Fusier CLA 2005-04-28 06:06:41 EDT
About comment 3: no it's not backwards. If user still want consider javadoc
comment as flat text, then he can do it by unsetting option "Process Javadoc
Comments".

But ,as soon as this option is set (which is the default), then compiler
considers that some part of javadoc comments can be considered as code
(typically @see references) and parse it to verify their accuracy.

This is obviously necessary while renaming types, methods and fields. With
"Process Javadoc Comments" option set, refactoring will rename all references
even those which are in javadoc comments for free (and it's sometimes really
appreciable...)

Note that javadoc.exe do the same to report warnings when references put after
@see, @link, etc. tags are not accurate.
Comment 6 Frederic Fusier CLA 2005-04-28 09:15:14 EDT
Fixed and released in HEAD.

Now Java Builder does not unset doc comment support when option unused import is
activated.

[jdt-core-internal]
Change done in AbstractImageBuilder.newCompiler() method.

Test case added in BasicBuildTests
Comment 7 Maxime Daniel CLA 2005-05-12 10:44:46 EDT
Verified for 3.1 M7 using build I20050509-2010 + jdt.core HEAD.
Comment 8 Frederic Fusier CLA 2005-06-16 03:37:57 EDT
*** Bug 100126 has been marked as a duplicate of this bug. ***
Comment 9 Frederic Fusier CLA 2006-07-07 05:49:44 EDT
*** Bug 149752 has been marked as a duplicate of this bug. ***
Comment 10 Markus Keller CLA 2008-11-05 14:00:58 EST
*** Bug 253750 has been marked as a duplicate of this bug. ***
Comment 11 Markus Keller CLA 2009-03-04 09:23:44 EST
*** Bug 266979 has been marked as a duplicate of this bug. ***
Comment 12 Eugen Paraschiv CLA 2011-08-03 04:26:41 EDT
I am able to reproduce this in 3.7 - an exception that only appears in the javadoc (throws XYException) will be automatically added to the imports of the class.