Skip to content

[java] LawOfDemeter: False positive with package-private access #2182

@linusjf

Description

@linusjf

#2160 (comment)

Affects PMD Version:
6.20.0

Rule:
LawOfDemeter.

Description:
Direct access of fields is flagged as static access. Direct access of fields should be permitted when allowed for package-private.

Code Sample demonstrating the issue:

import java.time.LocalDate;

public class Person {
  LocalDate birthday;

  public static int compareByAge(Person a, Person b) {
    return a.birthday.compareTo(b.birthday);
  }
}

Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]

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