#563 unable to load class info when inner class in super class

release_5.0
open
nobody
None
5
2014-01-16
2009-04-21
Conny K.
No

Hello,

I know there have been lots of similar issues and I've read most (if not all) of them. But still something seems to be wrong.

We have a class A with an Exception E declared as public static inner class. Then we have a class B derived from class A with a method m throwing E. If we now use @throw tag in the javadoc of m, we get the "unable to load class information" error (in fact we get the german version "Klassen-Information für E nicht verfügbar.")

An @throw tag in the javadoc of a similar method in A does not cause any Problems.

We use Checkstyle 4.3. I also tried 4.4 and 5.0 - all the same.

Example:

Class A:

public class A
{
/*
* @throws E no problem here

/
public synchronized void m1() throws E
{
throw new E("just a demo");
}

public static class E extends Exception
{
public E(String message)
{
super(message);
}
}
}

Class B:

public class B extends A
{
/*
* @throws E THIS CAUSES THE PROBLEM

/
public synchronized void m() throws E
{
throw new E("just a demo");
}
}

Checkstyle configuration:
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.2//EN"
"http://www.puppycrawl.com/dtds/configuration_1_2.dtd">

<module name="Checker">
<module name="TreeWalker">
<module name="RedundantThrows"/>
</module>
</module>

regards,
Conny

Discussion

  • Mark Hobson
    Mark Hobson
    2009-10-20

    I've experienced this in 5.0 even without subclassing. For example:

    public interface Foo {
    public static class FooException extends Exception {
    }
    void bar() throws FooException;
    }

    With config:

    <module name="Checker">
    <module name="TreeWalker">
    <module name="RedundantThrows"/>
    </module>
    </module>

    Produces: "java.lang.RuntimeException: Unable to get class information for FooException."

    Looks like a regression as this bug has been reported and fixed for earlier versions (1220726), possibly introduced by the fix for 1379666. A quick run through the debugger shows that RedundantThrowsCheck is missing its current class name, so inner classes cannot be resolved.

    A workaround is to declare the exception using the outer class, e.g.:

    public interface Foo {
    public static class FooException extends Exception {
    }
    void bar() throws Foo.FooException;
    }