#1027 PMD Ant: java.lang.ClassCastException

PMD-5.0.3
closed
None
PMD
3-Major
Bug
2013-04-05
2012-09-14
Anjana
No

Hi
we have moved from pmd from 4.5.2 jar to 5.0.0 jar and we get the below error

java.lang.ClassCastException: net.sourceforge.pmd.lang.rule.XPathRule cannot be cast to net.sourceforge.pmd.Rule
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:116)
at org.apache.tools.ant.Task.perform(Task.java:348)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

in pmd documentation it is mentioned that Renamed - net.sourceforge.pmd.rule.XPathRule to net.sourceforge.pmd.lang.rule.XPathRule

Could anyone suggest me what has to be done to fix this issue.

Thanks

Discussion

  • Ryan Gustafson

    Ryan Gustafson - 2012-09-14

    I would double check your classpath. Make sure you don't have both 4.x and 5.x on the classpath. XPathRule is an instance of Rule in both versions of PMD.

     
  • Comment has been marked as spam. 
    Undo

    You can see all pending comments posted by this user  here

    Anonymous - 2012-09-25

    I am getting same error when I run PMD 5.0.0 or PMD 5.0-alpha in my IVY driven ant environment. The error does not occure using PMD 5.0-alpha in my non-IVY driven ant environment. But I do not have any 4.x version of PMD on this machine. It seems that there is another incompatiblity. I noticed that PMD task loads using AntClassLoader wondering if that is causing some classes to exist in one class loader while others exist in another. That would cause a ClassCastException.

     
  • Andreas Dangel

    Andreas Dangel - 2013-03-17
    • summary: java.lang.ClassCastException --> PMD Ant: java.lang.ClassCastException
    • status: open --> in-progress
    • assigned_to: Andreas Dangel
    • module: --> PMD
    • milestone: --> PMD-5.0.3
    • priority: 5 --> 3-Major
    • type: --> Bug
    • affects_version: -->
     
  • Andreas Dangel

    Andreas Dangel - 2013-03-17

    I could reproduce the problem, if you use the classpath element for the PMD task in ant, e.g.

        <target name="testClasspath">
            <pmd>
                <ruleset>classpathtest/ruleset.xml</ruleset>
                <classpath>
                    <pathelement path="${pmd.home}/target/classes"/>
                    <pathelement path="${pmd.home}/target/test-classes"/>
                    <pathelement path="${pmd.home}/target/test-classes/net/sourceforge/pmd/ant"/>
                </classpath>
            </pmd>
        </target>
    

    and you'll run with the same ant call other targets, that also call PMD.

    In PMD, we relied on the default settings for AntClassLoader to look at the parent class loader first. This works with ant version 1.8.1, that is used by PMD. So, I assume you use a different ant version.

    However, PMD now explicitly sets the parent class loader.

     
  • Andreas Dangel

    Andreas Dangel - 2013-03-17
    • status: in-progress --> closed
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks