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

Close

#703 "Unable to get class information" for RedundantThrows check

release_5.0
wont-fix
nobody
None
1
2015-01-15
2013-08-12
Rudolf Schürer
No

Checkstyle 5.6 reports the following bogus error:

D:\cstest\src\com\a\Test.java:4:40: warning: Unable to get class information for TestException.

even though TestException is available as source in the same package. Note that this is different from e.g. issue 630, because no nested classes are involved.

Source for Test.java:

package com.a;

public class Test {
    public void test(boolean b) throws TestException {
        if (b) {
            throw new TestException();
        }
    }
}

Source for TestException.java:

package com.a;

public class TestException extends Exception {
    public TestException() {
    }
}

rules.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN" "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name="Checker">
  <property name="severity" value="warning"/>
  <module name="TreeWalker">
    <module name="RedundantThrows"/>
  </module>
</module>

Discussion

  • Oliver Burn
    Oliver Burn
    2013-08-12

    You need to configure the Checkstyle classpath to be able to locate the missing class file. Checkstyle does not use the source code path, but only the classpath. See the classpathref attribute of the ANT task (http://checkstyle.sourceforge.net/anttask.html).

     
  • So, you are saying I need to compile the source which I'd like to check and add the resulting class files to the classpath for Checkstyle? And this is only necessary to make this particular check (RedundantThrows) work correctly, because all other checks seem to work without this hack?

    This is quite cumbersome as well as unintuitive. At least it should be documented somewhere.

     
  • Oliver Burn
    Oliver Burn
    2013-08-13

    • status: open --> wont-fix
     
  • Oliver Burn
    Oliver Burn
    2013-08-13

    That is correct, sorry you find in non-intuitive.