New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[java] Processing error (ClassCastException) if a TYPE_USE annotation is used on a base class in the "extends" clause #1369

Closed
vovkss opened this Issue Oct 5, 2018 · 0 comments

Comments

Projects
None yet
2 participants
@vovkss
Contributor

vovkss commented Oct 5, 2018

Affects PMD Version: 6.8.0

Rule: SignatureDeclareThrowsException (maybe others, too)

Description:

An annotation used on a base class in the extends clause causes PMD to fail with a ClassCastException.

Code Sample demonstrating the issue:

package com.example;

import java.lang.annotation.ElementType;
import java.lang.annotation.Target;

public final class Namespace {

    @Target(ElementType.TYPE_USE)
    public @interface Weird {
    }

    public class WeirdException extends @Weird Exception {
    }

}

Output:

[INFO] --- maven-pmd-plugin:3.10.0:pmd (pmd) @ re-managers-impl ---
[INFO] Analysis cache invalidated, rulesets changed.
[INFO] Analysis cache invalidated, execution classpath changed.
[WARNING] Exception applying rule SignatureDeclareThrowsException on file .../Namespace.java, continuing with next rule
java.lang.ClassCastException: class net.sourceforge.pmd.lang.java.ast.ASTAnnotation cannot be cast to class net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceType (net.sourceforge.pmd.lang.java.ast.ASTAnnotation and net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceType are in unnamed module of loader org.codehaus.plexus.classworlds.realm.ClassRealm @c7e16b1)
    at net.sourceforge.pmd.lang.java.rule.design.SignatureDeclareThrowsExceptionRule.visit (SignatureDeclareThrowsExceptionRule.java:80)
    at net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration.jjtAccept (ASTClassOrInterfaceDeclaration.java:55)
    at net.sourceforge.pmd.lang.java.ast.AbstractJavaNode.childrenAccept (AbstractJavaNode.java:60)
    at net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.visit (AbstractJavaRule.java:84)
    at net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.visit (AbstractJavaRule.java:130)
    at net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceBodyDeclaration.jjtAccept (ASTClassOrInterfaceBodyDeclaration.java:43)
    at net.sourceforge.pmd.lang.java.ast.AbstractJavaNode.childrenAccept (AbstractJavaNode.java:60)
    at net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.visit (AbstractJavaRule.java:84)
    at net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.visit (AbstractJavaRule.java:125)
    at net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceBody.jjtAccept (ASTClassOrInterfaceBody.java:32)
    at net.sourceforge.pmd.lang.java.ast.AbstractJavaNode.childrenAccept (AbstractJavaNode.java:60)
    at net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.visit (AbstractJavaRule.java:84)
    at net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.visit (AbstractJavaRule.java:95)
    at net.sourceforge.pmd.lang.java.rule.design.SignatureDeclareThrowsExceptionRule.visit (SignatureDeclareThrowsExceptionRule.java:87)
    at net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration.jjtAccept (ASTClassOrInterfaceDeclaration.java:55)
    at net.sourceforge.pmd.lang.java.ast.AbstractJavaNode.childrenAccept (AbstractJavaNode.java:60)
    at net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.visit (AbstractJavaRule.java:84)
    at net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.visit (AbstractJavaRule.java:280)
    at net.sourceforge.pmd.lang.java.ast.ASTTypeDeclaration.jjtAccept (ASTTypeDeclaration.java:37)
    at net.sourceforge.pmd.lang.java.ast.AbstractJavaNode.childrenAccept (AbstractJavaNode.java:60)
    at net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.visit (AbstractJavaRule.java:84)
    at net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.visit (AbstractJavaRule.java:255)
    at net.sourceforge.pmd.lang.java.rule.design.SignatureDeclareThrowsExceptionRule.visit (SignatureDeclareThrowsExceptionRule.java:54)
    at net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.visitAll (AbstractJavaRule.java:39)
    at net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.apply (AbstractJavaRule.java:27)
    at net.sourceforge.pmd.lang.rule.AbstractDelegateRule.apply (AbstractDelegateRule.java:336)
    at net.sourceforge.pmd.RuleSet.apply (RuleSet.java:499)
    at net.sourceforge.pmd.RuleSets.apply (RuleSets.java:143)
    at net.sourceforge.pmd.SourceCodeProcessor.processSource (SourceCodeProcessor.java:184)
    at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode (SourceCodeProcessor.java:96)
    at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode (SourceCodeProcessor.java:51)
    at net.sourceforge.pmd.processor.PmdRunnable.call (PmdRunnable.java:78)
    at net.sourceforge.pmd.processor.PmdRunnable.call (PmdRunnable.java:24)
    at java.util.concurrent.FutureTask.run (FutureTask.java:264)
    at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:515)
    at java.util.concurrent.FutureTask.run (FutureTask.java:264)
    at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1128)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:628)
    at java.lang.Thread.run (Thread.java:834)
[INFO] Analysis cache updated

[ERROR] PMD processing errors:
[ERROR] Namespace.java: class net.sourceforge.pmd.lang.java.ast.ASTAnnotation cannot be cast to class net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceType (net.sourceforge.pmd.lang.java.ast.ASTAnnotation and net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceType are in unnamed module of loader org.codehaus.plexus.classworlds.realm.ClassRealm @c7e16b1)

Running PMD through: Maven

@jsotuyod jsotuyod added the a:bug label Oct 5, 2018

@jsotuyod jsotuyod added this to the 6.9.0 milestone Oct 5, 2018

@jsotuyod jsotuyod self-assigned this Oct 15, 2018

@jsotuyod jsotuyod added the has:pr label Oct 15, 2018

jsotuyod added a commit to Monits/pmd that referenced this issue Oct 15, 2018

jsotuyod added a commit to Monits/pmd that referenced this issue Oct 15, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment