Skip to content

[java] @ThisModifier compare not working #902

@d1ss0nanz

Description

@d1ss0nanz

Affects PMD Version:
6.0.2

Description:
I'm trying to write a custom XPath rule that is based on detecting
//PrimaryExpression[PrimaryPrefix/@ThisModifier='true']
Doesn't match. Neither does:
//PrimaryExpression/PrimaryPrefix[@ThisModifier='true']
While in designer //PrimaryExpression/PrimaryPrefix selects the right nodes and "ThisModifier = true".

Code Sample demonstrating the issue:

public class MockCOD_Enum extends MockCOD
{
    private EnumTestMode testEnum = EnumTestMode.ENUM_1;
    private List<EnumTestMode> enumList = new ArrayList<>();
    private List<EnumTestMode> enumListNonEmpty =
        new ArrayList<>(Arrays.asList(EnumTestMode.ENUM_1, EnumTestMode.ENUM_2));

    @Override
    public int hashCode()
    {
        final int prime = 31;
        int result = super.hashCode();
        result = prime * result + ((testEnum == null) ? 0 : testEnum.hashCode());
        return result;
    }

    @Override
    public boolean equals(final Object obj)
    {
        if (this == obj)
        {
            return true;
        }
        if (!super.equals(obj))
        {
            return false;
        }
        if (!(obj instanceof MockCOD_Enum))
        {
            return false;
        }

        final MockCOD_Enum other = (MockCOD_Enum) obj;
        return testEnum == other.testEnum;
    }

    /**
     * TODO: JavaDoc
     * 
     * @return TODO
     */
    public EnumTestMode getEnum()
    {
        return this.testEnum;
    }

    /**
     * TODO: JavaDoc
     * 
     * @param testMode TODO
     */
    public void setEnum(final EnumTestMode testMode)
    {
        testEnum = testMode;
    }
}

Running PMD through:
Designer

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:questionRequest for information that doesn't necessarily entail changes to the code basein:xpathRelating to xpath support at large, eg Jaxen / Saxon, custom functions, attribute resolution

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions