Rule Set:
<rule ref="rulesets/java/design.xml/ConstructorCallsOverridableMethod"/>
Description:
The code below gives a false positive for the rule ConstructorCallsOverridableMethodRule for "dangerous" methods called from lambda expressions. I believe this is a false positive, because the method is not actually called during the constructor invocation. Also, replacing the lambda expressions by anonymous class does not give the violation.
Code Sample demonstrating the issue:
public class Foo {
public Foo(String s) {
addActionListener(() -> bar());
}
public void bar() {}
}
Running PMD through: CLI
C:\pmd\bin>pmd.bat -d FalsePositive.java -f xml -R rulesets/java/design.xml/ConstructorCallsOverridableMethod
Outputs:
<?xml version="1.0" encoding="UTF-8"?>
<pmd version="5.6.1" timestamp="2017-05-23T02:44:45.868">
<file name="C:\pmd\bin\FalsePositive.java">
<violation beginline="3" endline="3" begincolumn="27" endcolumn="31" rule="Const
ructorCallsOverridableMethod" ruleset="Design" class="Foo" method="Foo" external
InfoUrl="https://pmd.github.io/pmd-5.6.1/pmd-java/rules/java/design.html#Constru
ctorCallsOverridableMethod" priority="1">
Overridable method 'bar' called during object construction
</violation>
</file>
</pmd>
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4