Maven 1.x Checkstyle Plugin

Unable to get class information for custom exceptions

Details

  • Type: Bug Bug
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: 2.3
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Environment:
    maven-1.0-rc2
  • Number of attachments :
    0

Description

checkstyle reports an error "Unable to get class information" for custom exceptions within the same project. it is able to load exceptions that are listed as dependencies for the project, but not for other exceptions. one workaround is to only use throws Exception in the signiture, but that's really a hack.

Issue Links

Activity

Hide
Pål Brattberg added a comment -

I may have the time to look at this at a later time, but for now, here is a work around which may or may not help you out.

http://www.palbrattberg.com/index.php?p=46

Show
Pål Brattberg added a comment - I may have the time to look at this at a later time, but for now, here is a work around which may or may not help you out. http://www.palbrattberg.com/index.php?p=46
Hide
Sean Gay added a comment -

If the report is run after a clean the problem occurs, if the classes are compiled in your target directory then checkstyle can find the custom class information.

It may be a little hassle until a fix is completed to do this rather than the post report generation goal mentioned in the previous comment.

Show
Sean Gay added a comment - If the report is run after a clean the problem occurs, if the classes are compiled in your target directory then checkstyle can find the custom class information. It may be a little hassle until a fix is completed to do this rather than the post report generation goal mentioned in the previous comment.
Hide
Jeff Jensen added a comment -

We still have this problem with plugin 2.5 and 3.0 (CS 3.5 and 4.0). Does anyone else still have this problem?

Is there a known final fix for this (or is it the 2004 blog entry in the prior comment?)?

In trying to find a common cause, so far have only found these coincidences or symptoms:
1) The cross reference report creates links to the exception classes that CS flags as unable to find.
2) The cross reference report does not create links to the exception classes that CS does not flag as not found.

Show
Jeff Jensen added a comment - We still have this problem with plugin 2.5 and 3.0 (CS 3.5 and 4.0). Does anyone else still have this problem? Is there a known final fix for this (or is it the 2004 blog entry in the prior comment?)? In trying to find a common cause, so far have only found these coincidences or symptoms: 1) The cross reference report creates links to the exception classes that CS flags as unable to find. 2) The cross reference report does not create links to the exception classes that CS does not flag as not found.
Hide
Lukas Theussl added a comment -

Jeff, could you attach a small test project? I don't know how to reproduce this.

Show
Lukas Theussl added a comment - Jeff, could you attach a small test project? I don't know how to reproduce this.
Hide
Jeff Jensen added a comment -

Sorry for such a tardy response Lukas!

I started trying a small project to reproduce, and had troubles with doing so. I noticed that the problem was not consistent - happened on our prod build server and (IIRC) one of my workstations, but not on another. Regretfully, I also have not had much time to track it down.

Recently, I moved it to a new prod build server (hence, new setup) and the problem no longer occurs. The config files are the same (pulled from SCM), but clean repo may have made the difference.

I made another change from running multiproject:site to do all subs to running each sub on its own Maven run and then multiproject:site only for the dashboard goal and xdocs. (I made this change because of multiproject's much slower performance and problems with such a long run and so much code).

Based on all this, I have no recipe nor the problem anymore.

If no one else has this problem anymore, perhaps this entry is a candidate for "closed - unreproducible"?

Show
Jeff Jensen added a comment - Sorry for such a tardy response Lukas! I started trying a small project to reproduce, and had troubles with doing so. I noticed that the problem was not consistent - happened on our prod build server and (IIRC) one of my workstations, but not on another. Regretfully, I also have not had much time to track it down. Recently, I moved it to a new prod build server (hence, new setup) and the problem no longer occurs. The config files are the same (pulled from SCM), but clean repo may have made the difference. I made another change from running multiproject:site to do all subs to running each sub on its own Maven run and then multiproject:site only for the dashboard goal and xdocs. (I made this change because of multiproject's much slower performance and problems with such a long run and so much code). Based on all this, I have no recipe nor the problem anymore. If no one else has this problem anymore, perhaps this entry is a candidate for "closed - unreproducible"?
Hide
Ken Weiner added a comment -

I am having this problem too. The comment Sean Gay worked for me (running maven java:compile before running maven checkstyle:report).

Show
Ken Weiner added a comment - I am having this problem too. The comment Sean Gay worked for me (running maven java:compile before running maven checkstyle:report).
Hide
Dennis Lundberg added a comment -

This is a class loader issue with Checkstyle. I'm facing the same problems in the JetStyle plugin for IntelliJ IDEA. The Checkstyle checker need to be told which (context) class loader to use and that class loader needs to include all the dependencies for the project.

Here's a snippet of code from the JetStyle plugin that might shed some light on things:

try {
            Configuration checkstyleConfiguration =
                    ConfigurationLoader.loadConfiguration(configFile, configuration);

            // Create the checker
            checker = new Checker();
            checker.configure(checkstyleConfiguration);
            // Put it into context
            DefaultContext context = new DefaultContext();
//            @todo Figure out how to get a nice classloader from the IDEA project
//            final ClassLoader loader = project.getComponent(??);
//            context.add("classloader", loader);
            checker.contextualize(context);
        }
        catch (CheckstyleException ce) {
            throw new AbortException("Checkstyle error (" + ce.toString() + ")",
                    AbortException.ERROR);
        }

The code that is commented out needs to get its hands on a class loader from the pom somehow.

Show
Dennis Lundberg added a comment - This is a class loader issue with Checkstyle. I'm facing the same problems in the JetStyle plugin for IntelliJ IDEA. The Checkstyle checker need to be told which (context) class loader to use and that class loader needs to include all the dependencies for the project. Here's a snippet of code from the JetStyle plugin that might shed some light on things:
try {
            Configuration checkstyleConfiguration =
                    ConfigurationLoader.loadConfiguration(configFile, configuration);

            // Create the checker
            checker = new Checker();
            checker.configure(checkstyleConfiguration);
            // Put it into context
            DefaultContext context = new DefaultContext();
//            @todo Figure out how to get a nice classloader from the IDEA project
//            final ClassLoader loader = project.getComponent(??);
//            context.add("classloader", loader);
            checker.contextualize(context);
        }
        catch (CheckstyleException ce) {
            throw new AbortException("Checkstyle error (" + ce.toString() + ")",
                    AbortException.ERROR);
        }
The code that is commented out needs to get its hands on a class loader from the pom somehow.
Hide
David Hittner added a comment -

In my experience, this happens fairly constantly using Eclipse 3.1.1 with eclipse-cs plugin 4.0.93.

It ONLY happens when the class method has a throws clause that throws MULTIPLE exception types, and a custom exception is one (or more) of the thrown exceptions.

A throws clause with a single custom exception works properly.

A quick-and-dirty workaround (as has been noted) is to reduce the throws clause to a single thrown exception type, but this not necessarily a desirable 'fix', as it reduces the catchable granularity with the same JavaDoc impact.

Lukas, is this enough information to reproduce the problem, or do you still need a test project?

Show
David Hittner added a comment - In my experience, this happens fairly constantly using Eclipse 3.1.1 with eclipse-cs plugin 4.0.93. It ONLY happens when the class method has a throws clause that throws MULTIPLE exception types, and a custom exception is one (or more) of the thrown exceptions. A throws clause with a single custom exception works properly. A quick-and-dirty workaround (as has been noted) is to reduce the throws clause to a single thrown exception type, but this not necessarily a desirable 'fix', as it reduces the catchable granularity with the same JavaDoc impact. Lukas, is this enough information to reproduce the problem, or do you still need a test project?
Hide
Maurice le Rutte added a comment -

I have the same problem, but with a single, FQN'ed exception. Works fine in Eclipse 3.2 with plugin, but fails in Ant.

[checkstyle] Running Checkstyle 4.2 on 11 files
[checkstyle] H:\projects\attic-cards\src\main\com\cuhka\attic\renderer\RendererFactory.java:0: Got an exception - java.lang.RuntimeException: Unable to get class information for @throws tag 'com.cuhka.attic.renderer.RendererFactoryException'.

Code:
/**

  • Get the renderer for a figure.
  • @param figureClass figure class to get renderer for
  • @return renderer class
  • @throws com.cuhka.attic.renderer.RendererFactoryException on error
    */
    @SuppressWarnings("unchecked")
    public synchronized FigureRenderer getRenderer(Class<? extends Figure> figureClass)
    throws com.cuhka.attic.renderer.RendererFactoryException {
    }
Show
Maurice le Rutte added a comment - I have the same problem, but with a single, FQN'ed exception. Works fine in Eclipse 3.2 with plugin, but fails in Ant. [checkstyle] Running Checkstyle 4.2 on 11 files [checkstyle] H:\projects\attic-cards\src\main\com\cuhka\attic\renderer\RendererFactory.java:0: Got an exception - java.lang.RuntimeException: Unable to get class information for @throws tag 'com.cuhka.attic.renderer.RendererFactoryException'. Code: /**
  • Get the renderer for a figure.
  • @param figureClass figure class to get renderer for
  • @return renderer class
  • @throws com.cuhka.attic.renderer.RendererFactoryException on error */ @SuppressWarnings("unchecked") public synchronized FigureRenderer getRenderer(Class<? extends Figure> figureClass) throws com.cuhka.attic.renderer.RendererFactoryException { }
Hide
Anders Sveen added a comment -

I'm not sure but I think it is the same error. I get the same error on ServletException (which is in the classpath) and it only happens on my build server. My development PC with Windows works just fine.

I'm on Maven 2.0.3.

Show
Anders Sveen added a comment - I'm not sure but I think it is the same error. I get the same error on ServletException (which is in the classpath) and it only happens on my build server. My development PC with Windows works just fine. I'm on Maven 2.0.3.
Hide
Anders Sveen added a comment -

Changing the scope from provided to compile fixed the problem. It makes maven include the file in the war, but for the Servlet API that's no biggie. Other libs might cause more trouble.

Show
Anders Sveen added a comment - Changing the scope from provided to compile fixed the problem. It makes maven include the file in the war, but for the Servlet API that's no biggie. Other libs might cause more trouble.
Hide
Lukas Theussl added a comment -

Please note that this issue is for the Maven 1 checkstyle plugin, for the m2 plugin you should go to http://jira.codehaus.org/browse/MCHECKSTYLE.

Show
Lukas Theussl added a comment - Please note that this issue is for the Maven 1 checkstyle plugin, for the m2 plugin you should go to http://jira.codehaus.org/browse/MCHECKSTYLE.
Hide
zhongbing added a comment -

I have got this problem. I used the ant to call checkstyle, then I got the problem:Got an exception - java.lang.RuntimeException: Unable to get class information for @throws tag 'ServletException'.

The cause is that checkstyle can't find out the exception class in classpath. So It only needs to add the jar of the exception class to the classpath. For example:

<checkstyle config="${tools.checkstyle.ruleset}" failOnViolation="false" failureProperty="checkstyle.failure">
<classpath>
<path refid="classpath.project.lib" />
<path refid="classpath.tools.libs" />
<path refid="classpath.catalina" />
</classpath>
<formatter type="xml" tofile="${report.checkstyleReport.xml}" />
<fileset dir="${project.src}" includes="*/.java" />
</checkstyle>

I add the <path> in classpath, it will run successfully.

Show
zhongbing added a comment - I have got this problem. I used the ant to call checkstyle, then I got the problem:Got an exception - java.lang.RuntimeException: Unable to get class information for @throws tag 'ServletException'. The cause is that checkstyle can't find out the exception class in classpath. So It only needs to add the jar of the exception class to the classpath. For example: <checkstyle config="${tools.checkstyle.ruleset}" failOnViolation="false" failureProperty="checkstyle.failure"> <classpath> <path refid="classpath.project.lib" /> <path refid="classpath.tools.libs" /> <path refid="classpath.catalina" /> </classpath> <formatter type="xml" tofile="${report.checkstyleReport.xml}" /> <fileset dir="${project.src}" includes="*/.java" /> </checkstyle> I add the <path> in classpath, it will run successfully.
Hide
Seth Gottlieb added a comment -

I have had this problem (using Ant) too and setting the path did not fix. It appears that the issue is that it cannot handle multiple @throws. I had @throws ServletException, IOException. When I changed it to just ServletException it worked fine. The major hint for me was that the error message had a comma on the end: 'Unable to get class information for @throws tag 'javax.servlet.ServletException,'

Show
Seth Gottlieb added a comment - I have had this problem (using Ant) too and setting the path did not fix. It appears that the issue is that it cannot handle multiple @throws. I had @throws ServletException, IOException. When I changed it to just ServletException it worked fine. The major hint for me was that the error message had a comma on the end: 'Unable to get class information for @throws tag 'javax.servlet.ServletException,'
Hide
Sriharan Sithamparanathan added a comment -

I had a same issue when I run checkstyle task by using ant. Workaround is provide a customized exception classes in the checkstyle class path.
<checkstyle config="<<checkstyle.xml>>" failOnViolation="false">
<fileset dir="<<source path>>">
<include name="*/.java"/>
<exclude name="**/*Test.java" />
</fileset>
<classpath path="<<path of custom exception class>>"/>
<formatter type="xml" toFile="checkstyle-report.xml"/>
</checkstyle>

In the class path you can specify jar file path which is contains all the customized exception classes.

Example: if you have customized exception class InvalidNumberExcpetion class then that class should be in the checkstyle task class path.

Show
Sriharan Sithamparanathan added a comment - I had a same issue when I run checkstyle task by using ant. Workaround is provide a customized exception classes in the checkstyle class path. <checkstyle config="<<checkstyle.xml>>" failOnViolation="false"> <fileset dir="<<source path>>"> <include name="*/.java"/> <exclude name="**/*Test.java" /> </fileset> <classpath path="<<path of custom exception class>>"/> <formatter type="xml" toFile="checkstyle-report.xml"/> </checkstyle> In the class path you can specify jar file path which is contains all the customized exception classes. Example: if you have customized exception class InvalidNumberExcpetion class then that class should be in the checkstyle task class path.
Hide
Damien Collis added a comment -

I have noticed that even with the above work around, there is still an issue relating to custom exceptions that have been created as inner classes.

Show
Damien Collis added a comment - I have noticed that even with the above work around, there is still an issue relating to custom exceptions that have been created as inner classes.

People

Vote (22)
Watch (12)

Dates

  • Created:
    Updated: