pmd / pmd-eclipse-plugin

The pmd-eclipse-plugin integrates the source code analyzer PMD into the Eclipse IDE
Other
93 stars 43 forks source link

Rule Configuration Pref Page - PropertyDescriptor cannot be cast to Comparable #191

Closed iwanttoeatsogogiverymuch closed 6 months ago

iwanttoeatsogogiverymuch commented 7 months ago

Hello, I was using PMD Plug-in 7.0.0.v20240322-0920-r

in STS 4.22.0 RELASE and PMD version is also 7.0.0 (default set)

I managed to migrate 7.0.0 2 rc version of ruleset files to 7.0.0 version .

but when i click the rule in pmd Rule Configuration row in Tab, I randomly get this message

----------------------------------------------------------------------------------------------------------------------------------------
An error has occurred. See error log for more details.
class net.sourceforge.pmd.properties.PropertyDescriptor cannot be cast to class java.lang.Comparable (net.sourceforge.pmd.properties.PropertyDescriptor is in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @7ba41986; java.lang.Comparable is in module java.base of loader 'bootstrap') 
----------------------------------------------------------------------------------------------------------------------------------------

https://github.com/pmd/pmd-eclipse-plugin/blob/411cdc54c7ba6f047d00b01b2d16cbfc3d56e371/net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/preferences/br/RuleUIUtil.java#L117

I think it is a problem of plugin cuz there is no Nullcheck in this line. or maybe my configuration of ruleset xml file is not valid.

but i referenced official Github Document to write xml and below is my xml file content

    <rule name="AssignmentInOperand"
          language="java"
          since="1.03"
          message="Avoid assignments in operands"
          class="net.sourceforge.pmd.lang.java.rule.errorprone.AssignmentInOperandRule"
          externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#assignmentinoperand">
        <description>
            Avoid assignments in operands; this can make code more complicated and harder to read.
        </description>
        <priority>3</priority>
        <example>
            <![CDATA[
public void bar() {
    int x = 2;
    if ((x = getX()) == 3) {
      System.out.println("3!");
    }
}
]]>
        </example>
    </rule>

Is there anything I can fix?

image

And maybe some other error: getting Nullpointer Exception Property TypeId when I set rule of "AssignmentInOperand" in net.sourceforge.pmd.lang.java.rule.errorprone.AssignmentInOperandRule

adangel commented 7 months ago

Thanks for reporting. I can reproduce the NPEs by just opening the Rule Configuration page in the Preferences. And the Comparable-cast-problem when selecting the Rule "AssignmentInOperand".

Here are some stacktraces for reference:

java.lang.NullPointerException: Cannot invoke "net.sourceforge.pmd.properties.internal.PropertyTypeId.ordinal()" because "typeId" is null
    at net.sourceforge.pmd.eclipse.ui.preferences.br.RuleUIUtil.formatValueOn(RuleUIUtil.java:118)
    at net.sourceforge.pmd.eclipse.ui.preferences.br.RuleUIUtil.indexedPropertyStringFrom(RuleUIUtil.java:219)
    at net.sourceforge.pmd.eclipse.ui.preferences.br.ImageColumnDescriptor$1.valueFor(ImageColumnDescriptor.java:31)
    at net.sourceforge.pmd.eclipse.util.AbstractCellPainterBuilder.valueFor(AbstractCellPainterBuilder.java:100)
    at net.sourceforge.pmd.eclipse.util.StyledTextBuilder.adjust(StyledTextBuilder.java:38)
    at net.sourceforge.pmd.eclipse.util.StyledTextBuilder.access$0(StyledTextBuilder.java:36)
    at net.sourceforge.pmd.eclipse.util.StyledTextBuilder$1.handleEvent(StyledTextBuilder.java:71)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:89)
    at org.eclipse.swt.widgets.Display.sendEvent(Display.java:5855)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1529)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1555)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1538)
    at org.eclipse.swt.widgets.Tree.rendererRender(Tree.java:3409)
    at org.eclipse.swt.widgets.Tree.rendererRenderProc(Tree.java:3147)
    at org.eclipse.swt.widgets.Display.rendererRenderProc(Display.java:1716)
    at org.eclipse.swt.internal.gtk3.GTK3.gtk_main_do_event(Native Method)
    at org.eclipse.swt.widgets.Display.eventProc(Display.java:1598)
    at org.eclipse.swt.internal.gtk3.GTK3.gtk_main_iteration_do(Native Method)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:4514)
    at org.eclipse.jface.window.Window.runEventLoop(Window.java:823)
    at org.eclipse.jface.window.Window.open(Window.java:799)
    at org.eclipse.ui.internal.OpenPreferencesAction.run(OpenPreferencesAction.java:64)
...

java.lang.ClassCastException: class net.sourceforge.pmd.properties.PropertyDescriptor cannot be cast to class java.lang.Comparable (net.sourceforge.pmd.properties.PropertyDescriptor is in unnamed module of loade
r org.eclipse.osgi.internal.loader.EquinoxClassLoader @34deb959; java.lang.Comparable is in module java.base of loader 'bootstrap')
        at java.base/java.util.ComparableTimSort.countRunAndMakeAscending(ComparableTimSort.java:320)
        at java.base/java.util.ComparableTimSort.sort(ComparableTimSort.java:188)
        at java.base/java.util.Arrays.sort(Arrays.java:1041)
        at net.sourceforge.pmd.eclipse.ui.preferences.panelmanagers.FormArranger.rearrangeFor(FormArranger.java:207)
        at net.sourceforge.pmd.eclipse.ui.preferences.panelmanagers.FormArranger.arrangeFor(FormArranger.java:179)
        at net.sourceforge.pmd.eclipse.ui.preferences.panelmanagers.PerRulePropertyPanelManager.adapt(PerRulePropertyPanelManager.java:150)
        at net.sourceforge.pmd.eclipse.ui.preferences.panelmanagers.AbstractRulePanelManager.manage(AbstractRulePanelManager.java:122)
        at net.sourceforge.pmd.eclipse.ui.preferences.br.PMDPreferencePage2.selection(PMDPreferencePage2.java:431)
        at net.sourceforge.pmd.eclipse.ui.preferences.br.RuleTableManager.selectedItems(RuleTableManager.java:909)
        at net.sourceforge.pmd.eclipse.ui.preferences.br.AbstractTreeTableManager$6.selectionChanged(AbstractTreeTableManager.java:324)
        at org.eclipse.jface.viewers.Viewer$1.run(Viewer.java:151)
        at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:47)
        at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:174)
        at org.eclipse.jface.viewers.Viewer.fireSelectionChanged(Viewer.java:148)
        at org.eclipse.jface.viewers.StructuredViewer.updateSelection(StructuredViewer.java:2132)
        at org.eclipse.jface.viewers.ColumnViewer.updateSelection(ColumnViewer.java:1055)
        at org.eclipse.jface.viewers.StructuredViewer.handleSelect(StructuredViewer.java:1170)
        at org.eclipse.jface.viewers.CheckboxTreeViewer.handleSelect(CheckboxTreeViewer.java:299)
        at org.eclipse.jface.viewers.StructuredViewer$4.widgetSelected(StructuredViewer.java:1199)
        at org.eclipse.jface.util.OpenStrategy.fireSelectionEvent(OpenStrategy.java:262)
        at org.eclipse.jface.util.OpenStrategy$1.handleEvent(OpenStrategy.java:420)
        at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:89)
        at org.eclipse.swt.widgets.Display.sendEvent(Display.java:5855)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1529)
        at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:5065)
        at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:4517)
        at org.eclipse.jface.window.Window.runEventLoop(Window.java:823)
        at org.eclipse.jface.window.Window.open(Window.java:799)
        at org.eclipse.ui.internal.OpenPreferencesAction.run(OpenPreferencesAction.java:64)