Skip to content

[java] ImmutableField reports fields annotated with @FindBy and @FindBys (Selenium) #4020

@FSchliephacke

Description

@FSchliephacke

Affects PMD Version:
6.46.0

Rule:
ImmutableField
https://pmd.github.io/pmd-6.46.0/pmd_rules_java_design.html#immutablefield

Description:
Fields annotated with Selenium's @findby or @findbys are reported as "could be final", but they must not be final in order to be set by reflection.

Code Sample demonstrating the issue:

public class SomePage {
    @org.openqa.selenium.support.FindBy(id = "id1")
    private WebElement field1;

    @org.openqa.selenium.support.FindBys(value = {@org.openqa.selenium.support.FindByFindBy(id = "id2"), 
                                                                               @org.openqa.selenium.support.FindBy(xpath = "//div/table")})
    private WebElement table;
}

Expected outcome:
PMD reports a violation for fields field1 and table but that's wrong. That's a false positive.

Running PMD through:
Eclipse

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-positivePMD flags a piece of code that is not problematic

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions