Maven 1.x Checkstyle Plugin
  1. Maven 1.x Checkstyle Plugin
  2. MPCHECKSTYLE-1

Checkstyle Error - "Got an exception - java.lang.ClassCastException "

    Details

    • Type: New Feature New Feature
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.1
    • Fix Version/s: 2.0
    • Labels:
      None
    • Environment:
      JDK1.4.1_01 on Win2K
    • Number of attachments :
      0

      Description

      I have the latest HEAD build of Maven (built late 13th June GMT) and I am seeing this error 100s of times over in the checkstyle report.

      Error Line
      Got an exception - java.lang.ClassCastException 0

      Mailing list conversations:

      On Fri, Jun 13, 2003 at 04:40:44PM +0800, Willie Vu wrote:
      >> > Vincent,
      >> >
      >> > After I changed antlr plugin to use 2.7.2, I run into this problem:
      >> >
      >> > XXX.java: 0: Got an exception - java.lang.ClassCastException
      >> >
      >> > What is the problem?
      >> >
      >> > Willie
      >> >
      >> >
      >> I think, I've ran into the same problem - and nothing to do with
      >> the new checkstyle jar in my case. You cab check this by looking at
      >> the checkstyle reports in target - they are all right at me.
      >>
      >> The problem is that in my project.xml I'm using the
      >>
      >> <sourceDirectory>$

      {basedir}/src/java</sourceDirectory>
      >>
      >> convention, and in the checkstyle jsl, that formats the raw checkstyle
      >> report expects the sourceDirectory as a ${baseDir} relative value (line 56):
      >>
      >> <j:set var="fullSrcDir" value="${basedir}

      /$

      {pom.build.sourceDirectory}

      "/>

      >> And the whole jsl processing is went wrog from this, as the transformer
      >> would be working with a $

      {basedir}/ ${basedir}

      /<basedir_relative_filename>
      >> from here. Sometimes it causes exception, sometimes simply wrong.
      >>
      >> A dirty/quick cure to modify project.xml not to use $

      {basedir}

      (altough
      >> if you use reactor you may get troubles with that). I'm thinking how to
      >> patch the jsl script, just wrote this, maybe more knowledgeable jelliers
      >> are faster at fix than I am.
      >>
      >> incze

      However, my Project.xml uses relative "src/java" and I still have the same problem.

        Issue Links

          Activity

          Hide
          Vincent Massol added a comment -

          Email from Incze Lajos [incze@mail.matav.hu]:

          On Fri, Jun 13, 2003 at 04:40:44PM +0800, Willie Vu wrote:
          > Vincent,
          >
          > After I changed antlr plugin to use 2.7.2, I run into this problem:
          >
          > XXX.java: 0: Got an exception - java.lang.ClassCastException
          >
          > What is the problem?
          >
          > Willie
          >

          I think, I've ran into the same problem - and nothing to do with the new checkstyle jar in my case. You cab check this by looking at the checkstyle reports in target - they are all right at me.

          The problem is that in my project.xml I'm using the

          <sourceDirectory>$

          {basedir}/src/java</sourceDirectory>

          convention, and in the checkstyle jsl, that formats the raw checkstyle report expects the sourceDirectory as a ${baseDir} relative value (line 56):

          <j:set var="fullSrcDir" value="${basedir}

          /$

          {pom.build.sourceDirectory}

          "/>

          And the whole jsl processing is went wrog from this, as the transformer would be working with a $

          {basedir}/${basedir}

          /<basedir_relative_filename>
          from here. Sometimes it causes exception, sometimes simply wrong.

          A dirty/quick cure to modify project.xml not to use $

          {basedir}

          (altough if you use reactor you may get troubles with that). I'm thinking how to patch the jsl script, just wrote this, maybe more knowledgeable jelliers are faster at fix than I am.

          incze

          Show
          Vincent Massol added a comment - Email from Incze Lajos [incze@mail.matav.hu] : On Fri, Jun 13, 2003 at 04:40:44PM +0800, Willie Vu wrote: > Vincent, > > After I changed antlr plugin to use 2.7.2, I run into this problem: > > XXX.java: 0: Got an exception - java.lang.ClassCastException > > What is the problem? > > Willie > I think, I've ran into the same problem - and nothing to do with the new checkstyle jar in my case. You cab check this by looking at the checkstyle reports in target - they are all right at me. The problem is that in my project.xml I'm using the <sourceDirectory>$ {basedir}/src/java</sourceDirectory> convention, and in the checkstyle jsl, that formats the raw checkstyle report expects the sourceDirectory as a ${baseDir} relative value (line 56): <j:set var="fullSrcDir" value="${basedir} /$ {pom.build.sourceDirectory} "/> And the whole jsl processing is went wrog from this, as the transformer would be working with a $ {basedir}/${basedir} /<basedir_relative_filename> from here. Sometimes it causes exception, sometimes simply wrong. A dirty/quick cure to modify project.xml not to use $ {basedir} (altough if you use reactor you may get troubles with that). I'm thinking how to patch the jsl script, just wrote this, maybe more knowledgeable jelliers are faster at fix than I am. incze
          Hide
          Incze Lajos added a comment -

          OK. My previous diagnosis was all right (I've caught a real bug),
          but the main disease was different. And it's not maven. Studying
          the "target/checkstyle-raw-report.xml" which is produced by the
          ant:checkstyle target and especially the ant:formatter target
          inside, you can find lines like this one:

          <error line="87" column="5" severity="error" message="Method 'setLanguague' is not designed for extension - needs to be abstract, final or empty." source="com.puppycrawl.tools.checkstyle.checks.DesignForExtensionCheck"/>

          And this is the bad news: ' is good for html but bad for
          XML. So, the result file is not well formed. And yes, now
          I tested that this was the real problem, you can do it, too:

          1. Run site:generate
          2. Edit target/checkstyle-raw-report.xml and chacge all
          "'" to "'".
          3. Run xdoc
          4. Run site:fsdeploy or site:sshdeploy: and viola: you'll
          get a good checkstyle report.

          So we have two issues:
          1. maven checkstyle plugin's formatting jsl can't handle the
          $

          {basedir}

          /src/java construct in project.xml.
          2. ant:checkstyle/ant:formatter produces ill XML.

          Show
          Incze Lajos added a comment - OK. My previous diagnosis was all right (I've caught a real bug), but the main disease was different. And it's not maven. Studying the "target/checkstyle-raw-report.xml" which is produced by the ant:checkstyle target and especially the ant:formatter target inside, you can find lines like this one: <error line="87" column="5" severity="error" message="Method 'setLanguague' is not designed for extension - needs to be abstract, final or empty." source="com.puppycrawl.tools.checkstyle.checks.DesignForExtensionCheck"/> And this is the bad news: ' is good for html but bad for XML. So, the result file is not well formed. And yes, now I tested that this was the real problem, you can do it, too: 1. Run site:generate 2. Edit target/checkstyle-raw-report.xml and chacge all "'" to "'". 3. Run xdoc 4. Run site:fsdeploy or site:sshdeploy: and viola: you'll get a good checkstyle report. So we have two issues: 1. maven checkstyle plugin's formatting jsl can't handle the $ {basedir} /src/java construct in project.xml. 2. ant:checkstyle/ant:formatter produces ill XML.
          Hide
          Incze Lajos added a comment -

          As someone pointed out the ' problem was a false ring, it
          is a predefined XML entity.

          Further investigations show, that the real problem is some
          sort of influence (not obvious how) of the jdepend plugin report
          on the checkstyle plugin report.If the jdepend preceeds the
          checkstyle in the order of reports (which is the default if
          the POM does not contains explicitly the <reports> tag), then
          the checkstyle report fails. As a temporary workaround we
          should change the order of these two reports in the default,
          and anybody defining it's own <reports> in POM should place
          jdepend after checkstyle.

          incze

          Show
          Incze Lajos added a comment - As someone pointed out the ' problem was a false ring, it is a predefined XML entity. Further investigations show, that the real problem is some sort of influence (not obvious how) of the jdepend plugin report on the checkstyle plugin report.If the jdepend preceeds the checkstyle in the order of reports (which is the default if the POM does not contains explicitly the <reports> tag), then the checkstyle report fails. As a temporary workaround we should change the order of these two reports in the default, and anybody defining it's own <reports> in POM should place jdepend after checkstyle. incze
          Hide
          Steve Ovens added a comment -

          Don't know if this helps narrow it down, but if I run a checkstyle report as part of the "site" or "dist" goals, then I get the same problem - each source file reports a "Class Cast Exception" on line 0, and in the System error output I see the message "Can't find/access AST Node typecom.puppycrawl.tools.checkstyle.api.DetailAST".

          However, if I subsequently run a "maven checkstyle" by itself, the checkstyle executes correctly and the checkstyle-raw-report (and xml version of the report) are full of the expected checkstyle errors.

          My build source code is under src/java as specified in my project.xml file. (<sourceDirectory>src/java</sourceDirectory>)

          Show
          Steve Ovens added a comment - Don't know if this helps narrow it down, but if I run a checkstyle report as part of the "site" or "dist" goals, then I get the same problem - each source file reports a "Class Cast Exception" on line 0, and in the System error output I see the message "Can't find/access AST Node typecom.puppycrawl.tools.checkstyle.api.DetailAST". However, if I subsequently run a "maven checkstyle" by itself, the checkstyle executes correctly and the checkstyle-raw-report (and xml version of the report) are full of the expected checkstyle errors. My build source code is under src/java as specified in my project.xml file. (<sourceDirectory>src/java</sourceDirectory>)
          Hide
          Steve Ovens added a comment -

          I should note that swapping the order of reports (jdepend and checkstyle) (as suggested above by Incze Lajos [ 16/Jun/03 07:19 PM ]) did not have any effect - I get the ClassCastException reported either way.

          Show
          Steve Ovens added a comment - I should note that swapping the order of reports (jdepend and checkstyle) (as suggested above by Incze Lajos [ 16/Jun/03 07:19 PM ]) did not have any effect - I get the ClassCastException reported either way.
          Hide
          Mark Wilkinson added a comment -

          Just a hunch, but it might be worth a try. The Eclipse checkstyle plugin has a problem with the RedundantThrows check (com.puppycrawl.tools.checkstyle.checks.RedundantThrowsCheck) that causes it to say 'Unable to get class information for ...'. Perhaps the maven plugin is having trouble with the same check. Disabling the check should allow you to find out.

          There's discussion of the problem here: http://sourceforge.net/tracker/index.php?func=detail&aid=748678&group_id=80344&atid=559494

          Show
          Mark Wilkinson added a comment - Just a hunch, but it might be worth a try. The Eclipse checkstyle plugin has a problem with the RedundantThrows check (com.puppycrawl.tools.checkstyle.checks.RedundantThrowsCheck) that causes it to say 'Unable to get class information for ...'. Perhaps the maven plugin is having trouble with the same check. Disabling the check should allow you to find out. There's discussion of the problem here: http://sourceforge.net/tracker/index.php?func=detail&aid=748678&group_id=80344&atid=559494
          Hide
          Emmanuel Venisse added a comment -

          Done.

          Show
          Emmanuel Venisse added a comment - Done.
          Hide
          fabrizio giustina added a comment -

          Still having this problem using maven rc-1 and checkstyle plugin 2.2.

          The checkstyle report works if running alone (maven checkstyle). It doesn't work using more goals.
          This happens on different project, you can try using pom from displaytag
          http://cvs.sourceforge.net/viewcvs.py/displaytag/displaytag2/project.xml
          or jtidy
          http://cvs.sourceforge.net/viewcvs.py/jtidy/jtidy2/project.xml.

          Running on Windows JDK 1.4 version "1.4.1_03".

          In the log you get the following message for each class "Can't find/access AST Node typecom.puppycrawl.tools.checkstyle.api.DetailAST". And the report is filled with: "Got an exception - java.lang.ClassCastException ".

          Tryed removing report or goals: the ceckstyle plugin seem to work only if the checkstyle goal is run alone.

          Show
          fabrizio giustina added a comment - Still having this problem using maven rc-1 and checkstyle plugin 2.2. The checkstyle report works if running alone (maven checkstyle). It doesn't work using more goals. This happens on different project, you can try using pom from displaytag http://cvs.sourceforge.net/viewcvs.py/displaytag/displaytag2/project.xml or jtidy http://cvs.sourceforge.net/viewcvs.py/jtidy/jtidy2/project.xml . Running on Windows JDK 1.4 version "1.4.1_03". In the log you get the following message for each class "Can't find/access AST Node typecom.puppycrawl.tools.checkstyle.api.DetailAST". And the report is filled with: "Got an exception - java.lang.ClassCastException ". Tryed removing report or goals: the ceckstyle plugin seem to work only if the checkstyle goal is run alone.

            People

            • Assignee:
              Emmanuel Venisse
              Reporter:
              Nick Minutello
            • Votes:
              1 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: