I'm not sure if this problem is with PMD itself or maven pmd plugin, but sometimes I get following errors:
WARNING: Exception applying rule TooManyFields on file /path/to/DefaultInstanceId.java, continuing with next rule
java.lang.NullPointerException
at net.sourceforge.pmd.lang.java.rule.codesize.TooManyFieldsRule.visit(TooManyFieldsRule.java:55)
at net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.visitAll(AbstractJavaRule.java:31)
at net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.apply(AbstractJavaRule.java:25)
at net.sourceforge.pmd.lang.rule.AbstractDelegateRule.apply(AbstractDelegateRule.java:215)
at net.sourceforge.pmd.RuleSet.apply(RuleSet.java:307)
at net.sourceforge.pmd.RuleSets.apply(RuleSets.java:125)
at net.sourceforge.pmd.SourceCodeProcessor.processSource(SourceCodeProcessor.java:146)
at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:76)
at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:43)
at net.sourceforge.pmd.processor.PmdRunnable.call(PmdRunnable.java:79)
at net.sourceforge.pmd.processor.PmdRunnable.call(PmdRunnable.java:25)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
The class in question is quite simple:
public class DefaultInstanceId implements InstanceId {
private final String instanceId;
public DefaultInstanceId(String instanceId) {
this.instanceId = instanceId;
}
@Override
public String get() {
return instanceId;
}
}
This error happens only sometimes so it is quite frustrating to see that the PMD doesn't complain and then complains when the source code didn't change at all.
The mvn build is run without
Also, it doesn't always fail on this class, sometimes it is different, but always in the same module. As if some class in there caused PMD to behave irrationally.
This bug should be already fixed: https://sourceforge.net/p/pmd/bugs/1461/
The bugfix is available with PMD 5.3.7 and in the upcoming 5.4.2/5.5.0 releases.
You can get a SNAPSHOT from: https://sourceforge.net/projects/pmd/files/pmd/5.4.2-SNAPSHOT/