Menu

#885 pmd 5.0: Incorrect XPath Result in Rule Designer

open
pmd (543)
5
2012-10-07
2009-07-23
No

I was trying out the new rule designer in the snapshot of PMD 5.0, and found what I think is a bug.

To reproduce:

Run this query
//PrimaryExpression/PrimaryPrefix[@Image = 'this']

on this source code
public class Foo {
public void test() {
Object that = new Object();
if (this == that) { }
}
}

In the PMD 4.2.x rule designer, the correct behavior is observed: "ASTPrimaryPrefix at line 4 column 14". In PMD 5.0, however, the query results in "No matching nodes (hashcode)". This occurs both in XPath version 1.0 and 1.0 compatibility mode.

I realize this bug is against unreleased, beta software. Just thought I'd help catch a bug early on in the development process :)

Andy

Discussion

  • Ryan Gustafson

    Ryan Gustafson - 2009-07-23

    Thanks, I wasn't aware of this. I'll look into it. --Ryan

     
  • Ryan Gustafson

    Ryan Gustafson - 2009-07-24

    I'm not able to replicate this in 4.2.6, or trunk. The 'this' is not the image of the Node, it is the modifier, and has it's own attribute. The way to check is like so:

    //PrimaryExpression/PrimaryPrefix[@ThisModifier ='true']

    Does this work for you?

    Consider the following to help understand, use @SuperModifier on the last one:

    public class Foo {
    int x;
    public void test() {
    int a = x;
    int b = this.x;
    int c = super.x;
    }
    }

    This is just how the Java JavaCC grammar has been written (file Java.jjt). Look at the PrimaryPrefix definition for specifics.

     
  • Andy Throgmorton

    Sorry, I meant to say "Label" instead of "Image". The @Label provided the questionable behavior in the bug.

    And you are correct, the @ThisModifier query provides the correct behavior for both designer versions.

    The reason I tried the @Label notation is because the AST for the source code shows the following (under 4.2.x):

    <primaryprefix begincolumn="13" beginline="7" endcolumn="16" endline="7" label="this"></primaryprefix>

    I was surprised when @ThisModifier worked, since I didn't see the attribute in the PrimaryPrefix declaration.

     
  • Ryan Gustafson

    Ryan Gustafson - 2009-07-24

    Ahh, if I recall label was being used for the purposes of showing something in the designer. It was grafted into the AST structure in 4.2.x. For 5.0, the AST structure has been generalized for all Languages (e.g. Java, JSP, Javascript, XML, etc), and there is no such generic thing anymore. It's been moved into the "Dump" facilities, which are not part of the AST directly anymore, but are just a particular type of Visitor. Long story short, this is intended.

    As for the XML for the AST not showing the this/super modifiers, I'll look into that. It should for 4.2.x, as well as in 5.0. If it's not, I'll fix it.

    You can tell it's possible from the code, it's on the ASTPrimaryPrefix class, and the AttributeAxisIterator exposes 'uses' properties (among others). But one shouldn't have to dig that far to know that. I'll get the XML dump to be better.

    Also, I'm finding the presentation in the Designer to not be particular helpful for XPath rule designing. It should list things via Attribute name/value pairings, which makes things obvious, and stop using a fancy/misleading derived label scheme.

     
  • Ryan Gustafson

    Ryan Gustafson - 2009-07-24

    Hmm where did you get that XML?

    When I do Actions->Copy xml to clipboard, I get something like this in 4.2.x:

    <primaryprefix begincolumn="15" beginline="5" endcolumn="18" endline="5" image="" label="this" supermodifier="false" thismodifier="true"></primaryprefix>

    In 5.0 it looks like:

    <primaryprefix begincolumn="15" beginline="5" endcolumn="18" endline="5" findboundary="false" image="" supermodifier="false" thismodifier="true"></primaryprefix>

    Both have the Modifiers, and the case on attributes names starts with uppercase.

     
  • Andy Throgmorton

    Using latest version of Eclipse (3.5 I think - whatever Galileo is) on Windows Vista.
    Installed the PMD extension through Eclipse's "Install New Software..." interface - version 3.2.6.v200903300643. Then right-click on .java source file, PMD->Generate Abstract Syntax Tree.

     
  • Ryan Gustafson

    Ryan Gustafson - 2009-07-24

    Ahh, didn't realize that was there. Appears to be something custom to the Eclipse plugin. It's not using the built-in core capabilities. I'll see about changing it to use the core capabilities. It's very Java centric too, won't work well for 5.0 with other languages. Changing it to use Core will for that too.

    In the meantime, use Designer->Actions->Copy xml to clipboard, it does the right thing in both 4.2.x and 5.0.

     

Log in to post a comment.