Community
Participate
Working Groups
If there is a stale java doc comment preceding a method which no longer throws an exception, but the exception is declared with the @throws declaration, selecting "Organize Imports" from the Source menu will add import statement for the declared exception. Enter the following code into eclipse: ////////////////////////// public class ImportExample { /** * @throws NoSuchElementException */ public void op() { System.out.print( "" ); } } /////////////////////////// and select Source->Organize Imports. import java.util.NoSuchElementException; will be added in front of the class declaration.
What are your javadoc compiler settings ?
Javadoc tool allow user to specify in @throws tag any subclass of RuntimeException even if it's not thrown by the method. So, syntax is correct and if your javadoc compiler settings "Process Javadoc comments" is on (this is the default), compiler needs to bind this reference and so Organize Import correctly add the import to do it... In this case this is a duplicate of bug 92821 and there are several possibility here to workaround your problem: 1) you don't mind to parse javadoc, so unset "Process Javadoc comments" on your project 2) you want to parse javadoc comments but do not want to have an import for this specific reference, then write a fully qualified reference instead: * @throws java.util.NoSuchElementException Note that you can configure code assist to add fully qualified name and complete after * @throws NoSuchEle<|>
(In reply to comment #2) > Javadoc tool allow user to specify in @throws tag any subclass of > RuntimeException even if it's not thrown by the method. So, syntax is correct > and if your javadoc compiler settings "Process Javadoc comments" is on (this is > the default), compiler needs to bind this reference and so Organize Import > correctly add the import to do it... I didn't know this, sorry. I used NoSuchElementException just as an example, I really had an exception derived straight from Exception. Here is a better example: ////////////////// ImportExample.java ////////////////// package main; public class ImportExample { /** * @throws FakeException */ public void op() { System.out.print( "" ); } } /////////////////////// FakeException.java ////////////////////// package main.exception; public class FakeException extends Exception { } ///////////////////////////////////////////////////////////////// Still the same behaviour. And yes, "Process Javadoc comments" is on. If this is the desired behaviour, it is OK with me, I'll just have to learn how to use it properly. Thanks for the prompt response and all the excellent work you are doing for Eclipse.
(In reply to comment #3) > Still the same behaviour. And yes, "Process Javadoc comments" is on. If this is > the desired behaviour, it is OK with me, I'll just have to learn how to use it > properly. Yes, as explained in comment 2 and in bug 92821, this is the expected behavior. > Thanks for the prompt response and all the excellent work you are doing for > Eclipse. > You're welcome and thank you :-) *** This bug has been marked as a duplicate of 92821 ***