A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/817 below:

[java] UnnecessaryModifierRule crashes on valid code · Issue #817 · pmd/pmd · GitHub

Affects PMD Version: 6.0.0

Rule: UnnecessaryModifierRule

Description: when an annotation does not exist on the classpath UnnecessaryModifierRule.isSafeVarargs crashes with the following exception:

net.sourceforge.pmd.PMDException: Error while processing P:\projects\contrib\github-glide-v4\library\src\main\java\com\bumptech\glide\load\model\DataUrlLoader.java
	at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:101)
	at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:50)
	at net.sourceforge.pmd.processor.PmdRunnable.call(PmdRunnable.java:75)
	at net.sourceforge.pmd.processor.MonoThreadProcessor.runAnalysis(MonoThreadProcessor.java:29)
	at net.sourceforge.pmd.processor.AbstractPMDProcessor.processFiles(AbstractPMDProcessor.java:111)
	at net.sourceforge.pmd.PMD.processFiles(PMD.java:315)
	at net.sourceforge.pmd.ant.internal.PMDTaskImpl.doTask(PMDTaskImpl.java:192)
	at net.sourceforge.pmd.ant.internal.PMDTaskImpl.execute(PMDTaskImpl.java:276)
	at net.sourceforge.pmd.ant.PMDTask.execute(PMDTask.java:49)
	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
    ... (Gradle internals omitted for brevity)
Caused by: java.lang.NullPointerException
	at java.lang.Class.isAssignableFrom(Native Method)
	at net.sourceforge.pmd.lang.java.rule.codestyle.UnnecessaryModifierRule.isSafeVarargs(UnnecessaryModifierRule.java:154)
	at net.sourceforge.pmd.lang.java.rule.codestyle.UnnecessaryModifierRule.visit(UnnecessaryModifierRule.java:109)
	at net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration.jjtAccept(ASTMethodDeclaration.java:31)
	at net.sourceforge.pmd.lang.java.rule.JavaRuleChainVisitor.visit(JavaRuleChainVisitor.java:41)
	at net.sourceforge.pmd.lang.rule.AbstractRuleChainVisitor.visitAll(AbstractRuleChainVisitor.java:90)
	at net.sourceforge.pmd.RuleChain.apply(RuleChain.java:67)
	at net.sourceforge.pmd.RuleSets.apply(RuleSets.java:140)
	at net.sourceforge.pmd.SourceCodeProcessor.processSource(SourceCodeProcessor.java:181)
	at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:95)
	... 98 more

Investigation:
I downloaded the pmd-java sources and debugged the crash via JUnit tests:

Based on this information adding the following to my build.gradle solved the issue:

tasks.create('pmd', Pmd) {
	classpath = project.configurations.compile
}

While this actually fixes the crash, I don't think PMD should crash with an incomplete classpath, especially that method could default to false when the annotation is not known.

Code Sample demonstrating the issue:

class Foo {
    @Bar
    final void method() { }
}

(original code https://github.com/bumptech/glide/blob/e35a73b4e78f2f05dc5c1163b8083ac1b662b02f/library/src/main/java/com/bumptech/glide/load/model/DataUrlLoader.java#L153-L157)

Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]: Gradle, also JUnit tests via pmd-java sources

Sidenote: I did a quick check whether other isAssignableFrom calls are ok, and they all seem to be protected against nulls, but while searching I noticed UnusedImportsRule.check has a weird TypeNode.class.isAssignableFrom(node.getClass()) code in it, it could be node instanceof TypeNode. Same pattern in ClassTypeResolverTest.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4