giancosta86 / EasyPmd

Seamlessly integrates PMD into your NetBeans IDE
GNU General Public License v3.0
18 stars 5 forks source link

Exception when the controversial rule set is enabled #1

Open Zero3 opened 9 years ago

Zero3 commented 9 years ago

With Netbeans 8.0.2 and JDK 8, I get the following exception (caught by Netbeans) when the controversial default filter is enabled:

java.lang.ClassNotFoundException: net.sf.saxon.trans.XPathException
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.netbeans.ProxyClassLoader.loadClass(ProxyClassLoader.java:222)
Caused: java.lang.ClassNotFoundException: net.sf.saxon.trans.XPathException starting from ModuleCL@135e8d50[info.gianlucacosta.easypmd.easypmd] with possible defining loaders [ModuleCL@3baf84e7[org.netbeans.modules.html.validation]] and declared parents [org.netbeans.MainImpl$BootClassLoader@65b3120a, ModuleCL@311c0dec[org.openide.loaders], ModuleCL@7df4d42e[org.netbeans.spi.tasklist], ModuleCL@23e4c856[org.netbeans.modules.editor.guards], ModuleCL@33afffd[org.netbeans.modules.options.api], ModuleCL@3b315cf4[org.openide.dialogs], ModuleCL@27becd52[org.netbeans.api.annotations.common], ModuleCL@7cb8c3d8[org.openide.text], ModuleCL@6f3e4b1[org.netbeans.modules.javahelp], ModuleCL@933a863[org.openide.awt]]
    at org.netbeans.ProxyClassLoader.loadClass(ProxyClassLoader.java:224)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
Caused: java.lang.NoClassDefFoundError: net/sf/saxon/trans/XPathException
    at net.sourceforge.pmd.lang.rule.XPathRule.init(XPathRule.java:100)
    at net.sourceforge.pmd.lang.rule.XPathRule.getRuleChainVisits(XPathRule.java:85)
    at net.sourceforge.pmd.lang.rule.AbstractRule.usesRuleChain(AbstractRule.java:310)
    at net.sourceforge.pmd.lang.rule.AbstractRuleChainVisitor.initialize(AbstractRuleChainVisitor.java:135)
    at net.sourceforge.pmd.lang.rule.AbstractRuleChainVisitor.visitAll(AbstractRuleChainVisitor.java:53)
    at net.sourceforge.pmd.RuleChain.apply(RuleChain.java:66)
    at net.sourceforge.pmd.RuleSets.apply(RuleSets.java:122)
    at net.sourceforge.pmd.SourceCodeProcessor.processSource(SourceCodeProcessor.java:146)
    at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:76)
    at info.gianlucacosta.easypmd7.pmdscanner.LinkedPmdScanningStrategy.scanFile(LinkedPmdScanningStrategy.java:113)
    at info.gianlucacosta.easypmd7.pmdscanner.CacheBasedLinkedPmdScanningStrategy.scanFile(CacheBasedLinkedPmdScanningStrategy.java:52)
    at info.gianlucacosta.easypmd7.pmdscanner.PmdScanner.scanFile(PmdScanner.java:50)
    at info.gianlucacosta.easypmd7.ide.IdeScanner.scan(IdeScanner.java:147)
    at org.netbeans.modules.tasklist.impl.TaskIndexer.index(TaskIndexer.java:153)
    at org.netbeans.modules.parsing.spi.indexing.Indexable$MyAccessor$2.run(Indexable.java:161)
    at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater.runIndexer(RepositoryUpdater.java:283)
    at org.netbeans.modules.parsing.spi.indexing.Indexable$MyAccessor.index(Indexable.java:159)
[catch] at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$RefreshCifIndices.getDone(RepositoryUpdater.java:3911)
    at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$Work.doTheWork(RepositoryUpdater.java:3267)
    at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$Task._run(RepositoryUpdater.java:5810)
    at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$Task.access$5300(RepositoryUpdater.java:5476)
    at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$Task$3$1.run(RepositoryUpdater.java:5735)
    at org.netbeans.modules.parsing.impl.RunWhenScanFinishedSupport.performScan(RunWhenScanFinishedSupport.java:96)
    at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$Task$3.call(RepositoryUpdater.java:5731)
    at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$Task$3.call(RepositoryUpdater.java:5727)
    at org.netbeans.modules.masterfs.filebasedfs.utils.FileChangedManager.priorityIO(FileChangedManager.java:176)
    at org.netbeans.modules.masterfs.providers.ProvidedExtensions.priorityIO(ProvidedExtensions.java:360)
    at org.netbeans.modules.parsing.impl.Utilities.runPriorityIO(Utilities.java:74)
    at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$Task.run(RepositoryUpdater.java:5727)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1423)
    at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2033)
giancosta86 commented 9 years ago

Alas, I still can't reproduce this issue... what NetBeans bundle are you using? :) Are you still facing the problem? Have you installed additional plugins which might interfere?

Zero3 commented 9 years ago

I can reproduce by simply enabling the filter and clicking OK. The red warning icon then immediately appears at the bottom right of the screen in the status line (same place where update notifications / restart notifications pop up).

I'm quite sure I downloaded the Java SE bundle back when I installed Netbeans.

I got 41 "plugins" installed according to the plugin manager in Netbeans. Most of these are from the bundle, but I installed a few through the "Available Plugins" tab. I have no idea what to look for with regards to interference. Let me know if there is anything you would like me to try.

The Netbeans about page shows the following. Maybe it is of any help:

Product Version: NetBeans IDE 8.0.2 (Build 201411181905)
Updates: NetBeans IDE is updated to version NetBeans 8.0.2 Patch 2
Java: 1.8.0_45; Java HotSpot(TM) 64-Bit Server VM 25.45-b02
Runtime: Java(TM) SE Runtime Environment 1.8.0_45-b15
System: Windows 7 version 6.1 running on amd64; Cp1252; da_DK (nb)
giancosta86 commented 9 years ago

In order to reproduce the issue, I have just installed the latest NetBeans 8.0.2 (201411181905) for Java SE on a clean virtual machine with JDK 8, and:

As a consequence, I'd say there's some sort of classpath interference with other style-related plugins, probably with one referencing PMD...

Disabling a few checker plugins should make it easy to find out which of them caused the interference.

Zero3 commented 9 years ago

Thanks for looking into this. I will try disabling plugins in an attempt to track down a conflict. I will get back to you after trying.

giancosta86 commented 9 years ago

It seems that fixing this bug would require not to exclude Saxon and Xerces from EasyPmd's Maven dependencies, but that would cause bug #7, which is far worse. Therefore, I'll have to exclude them again, at least for now.

Zero3 commented 8 years ago

For your information, I tracked the exception to the AvoidLiteralsInIfCondition rule from PMD's controversial.xml ruleset:

<rule  name="AvoidLiteralsInIfCondition"
      language="java" since="4.2.6"
      message="Avoid using Literals in Conditional Statements"
      class="net.sourceforge.pmd.lang.rule.XPathRule"
      externalInfoUrl="${pmd.website.baseurl}/rules/java/controversial.html#AvoidLiteralsInIfCondition">
    <description>
Avoid using hard-coded literals in conditional statements. By declaring them as static variables
or private members with descriptive names maintainability is enhanced. By default, the literals "-1" and "0" are ignored.
More exceptions can be defined with the property "ignoreMagicNumbers".
    </description>
    <priority>3</priority>
    <properties>
      <property name="ignoreMagicNumbers" description="Comma-separated list of magic numbers, that should be ignored"
        type="String" value="-1,0"/>
      <property name="xpath">
        <value>
<![CDATA[
//IfStatement/Expression/*/PrimaryExpression/PrimaryPrefix/Literal
[not(NullLiteral)]
[not(BooleanLiteral)]
[empty(index-of(tokenize($ignoreMagicNumbers, ','), @Image))]
]]>
        </value>
      </property>
      <property name="version" value="2.0"/>
    </properties>
    <example>
<![CDATA[
private static final int MAX_NUMBER_OF_REQUESTS = 10;

public void checkRequests() {

    if (i == 10) {                        // magic number, buried in a method
      doSomething();
    }

    if (i == MAX_NUMBER_OF_REQUESTS) {    // preferred approach
      doSomething();
    }

    if (aString.indexOf('.') != -1) {}     // magic number -1, by default ignored
    if (aString.indexOf('.') >= 0) { }     // alternative approach

    if (aDouble > 0.0) {}                  // magic number 0.0
    if (aDouble >= Double.MIN_VALUE) {}    // preferred approach
}
]]>
    </example>
  </rule>

Edit: The same is true for OneDeclarationPerLine as noted in https://github.com/acanda/eclipse-pmd/issues/17.

rkraneis commented 6 years ago

This still happens with current EasyPMD on current NetBeans 8 dev :-/