Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[java] LawOfDemeter: False positive when casting to derived class #2189

Closed
linusjf opened this issue Dec 26, 2019 · 0 comments · Fixed by #2560
Closed

[java] LawOfDemeter: False positive when casting to derived class #2189

linusjf opened this issue Dec 26, 2019 · 0 comments · Fixed by #2560
Labels
a:false-positive PMD flags a piece of code that is not problematic
Milestone

Comments

@linusjf
Copy link

linusjf commented Dec 26, 2019

#2160 (comment)

Affects PMD Version:
6.20.0
Rule:
LawOfDemeter
Description:
Casting to derived class triggers method chaining error for this rule.
Code Sample demonstrating the issue:

package pmdtests;


  class TaskManager {
   
    private final List<ForkJoinTask<Integer>> tasks;

  
    public void cancelTasks(ForkJoinTask<Integer> cancelTask) {
      for (ForkJoinTask<Integer> task : tasks) {
        if (!task.equals(cancelTask)) {
          task.cancel(true);
          ((SearchNumberTask) task).writeCancelMessage();
        }
      }
    }
}
 

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

@linusjf linusjf changed the title [Java] False positive: Casting to derived class sets off method chaining error. [Java] False positive (LawOfDemeter): Casting to derived class sets off method chaining error. Dec 26, 2019
@adangel adangel changed the title [Java] False positive (LawOfDemeter): Casting to derived class sets off method chaining error. [java] LawOfDemeter: False positive when casting to derived class Jan 6, 2020
@adangel adangel added the a:false-positive PMD flags a piece of code that is not problematic label Jan 6, 2020
@adangel adangel added this to the 6.26.0 milestone Jul 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:false-positive PMD flags a piece of code that is not problematic
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants