Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#443 Nested Exception class not found for @throws

release_4.1
open
nobody
6
2014-02-09
2006-08-28
Daniel Schneller
No

In a parent class a custom exception is declared as a
nested class. In a child of the parent class a method
throws this exception.

public class A {
...
public static class MyException extends Exception {
...
}
}

public class B extends A {
...
/

@throws MyException

/
void method() throws MyException {
...
}
}

In this case checkstyle complains with a
RuntimeException about not being able to find a class
for the @throws tag.
The code compiles and works fine.
If I pull the Exception into its own file, the problem
does not occur.

I first reported this to the eclipse-cs plugin project,
however they told me this is a checkstyle problem.

Discussion

  • bungeman
    bungeman
    2006-12-05

    Logged In: YES
    user_id=1087782
    Originator: NO

    I have also run into this problem. My case looks like

    public class A {
    private void method() throws E {
    if (condition) throw new E();
    }

    public static class E extends Exception {
        E() { do stuff }
    }
    

    }

    this is a simpler case in that there is no B which derives from A. Hope that helps you track this down.

     
  • bungeman
    bungeman
    2006-12-14

    Logged In: YES
    user_id=1087782
    Originator: NO

    As an additional note, this causes eclipse to crash the second time checkstyle runs on the offending class, which is pretty bad.

     
  • bungeman
    bungeman
    2006-12-14

    Logged In: YES
    user_id=1087782
    Originator: NO

    Drat it, the code I gave is wrong. I believe a situation like the one I described earlier is ok, this is what was really going on:

    public class A {
    public class B {
    protected B() throws E { throw new E(); }
    }

    public static class E extends Exception {}
    

    }

    Checkstyle seems to give up and report the exception when it comes to "throws E".

     
  • bungeman
    bungeman
    2006-12-14

    Logged In: YES
    user_id=1087782
    Originator: NO

    By the way the exact error message (for the code in my previous comment) is:

    Got an exception - java.lang.RuntimeException: Unable to get class information for E.

     
  • Philip Aston
    Philip Aston
    2007-02-22

    Logged In: YES
    user_id=2117
    Originator: NO

    This is a regression of some sort.
    I see this problem when I use Checkstyle 4.3 from ANT, and a collegue reports the same with 4.2 from ANT.

    I don't see it when I use the Checkclipse Eclipse plugin (which uses 4.2).
    Works fine if I roll back to Checkstyle 3.4 from ANT.

    Its possible to work around by using FQNs in both the javadoc and the method signature, but that's plain ugly.

     
  • Philip Aston
    Philip Aston
    2007-02-22

    Logged In: YES
    user_id=2117
    Originator: NO

    This looks like a dup of 1656084. That was closed saying "add the classes to the CS classpath". I've tried this, it doesn't work (at least if they are added using a nested <classpath> element in the <checkstyle> ANT tag).

     
  • Roman Ivanov
    Roman Ivanov
    2014-02-06

    • labels: Core Framework --> Core Framework, JavaDoc