A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/1014 below:

False positive with lambda expression · Issue #1014 · pmd/pmd · GitHub

Affects PMD Version: 6.1.0

Rule: LawOfDemeter

Description: Since java 1.8 a lambda expression like this System.out::println can be used.
A "Potential violation of Law of Demeter (method chain calls)" is reported when a lambda expression is used as a parameter for a method.

Result files:

<?xml version="1.0" encoding="UTF-8"?>
<pmd xmlns="http://pmd.sourceforge.net/report/2.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://pmd.sourceforge.net/report/2.0.0 http://pmd.sourceforge.net/report_2_0_0.xsd"
    version="6.1.0" timestamp="2018-04-01T15:08:32.567">
<file name="F:\Project\Java\demeter\src\main\java\SimpleClass.java">
<violation beginline="5" endline="5" begincolumn="9" endcolumn="52" rule="LawOfDemeter" ruleset="Design" class="SimpleClass" method="simpleMethod" externalInfoUrl="https://pmd.github.io/pmd-6.1.0/pmd_rules_java_design.html#lawofdemeter" priority="3">
Potential violation of Law of Demeter (method chain calls)
</violation>
</file>
</pmd>

Code Sample demonstrating the issue:

import java.util.function.Consumer;

public class SimpleClass{
    public void simpleMethod() {
        anotherSimpleMethod(System.out::println, 10);
    }

    public <T> void anotherSimpleMethod(Consumer<T> consumer, T value) {
        consumer.accept(value);
    }
}

Running PMD through: Gradle

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'pmd'

repositories {
    mavenLocal()
    mavenCentral()
}

pmd{
    toolVersion = "6.1.0"
    ruleSetFiles = files("config/pmd/defaultRuleSet.xml")
    ruleSets = []
}
<ruleset 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Android Application Rules" 
    xmlns="http://pmd.sf.net/ruleset/1.0.0" xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd" xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0                         http://pmd.sf.net/ruleset_xml_schema.xsd">
    <description>Standard rule set</description>
    <rule ref="category/java/design.xml/LawOfDemeter"/>
</ruleset>

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