S1604 false positive when calling default method

34 views
Skip to first unread message

Brant Boehmann

unread,
Mar 9, 2018, 11:08:02 AM3/9/18
to SonarQube
S1604 raises a false positive when an anonymous inner class calls a default method. Converting to a lambda would cause a compile error because the lambda has a lack of knowledge about "this" and thus cannot call a default method.
I tried to file a ticket in Jira, but could not find a "New Issue" button. I'm assuming I don't have permissions or I overlooked it.

public class SonarTest {

    interface MyFunctional {
        default String defaultMethod() {
            return "defaultMethod";
        }

        String funcMethod();
    }

    public static void main(String[] args) {

        MyFunctional func = new MyFunctional() { //S1604 FP raised here
            @Override
            public String funcMethod() {
                return defaultMethod();
            }
        };

        System.out.println(func.funcMethod());

    }
}


Brant Boehmann

unread,
Mar 9, 2018, 11:24:00 AM3/9/18
to SonarQube
I should add that I'm running SonarQube 6.7.1 LTS and SonarJava 5.1.1

--
You received this message because you are subscribed to a topic in the Google Groups "SonarQube" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sonarqube/a9a5-UfTZZ4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sonarqube+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/927eb9c4-20fe-4c70-ba76-1cef18776fc9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nicolas Peru

unread,
Apr 27, 2018, 8:36:10 AM4/27/18
to Brant Boehmann, SonarQube
Hi, 

Thanks for the reproducer, this is indeed a FP, more details on the ticket to fix it : https://jira.sonarsource.com/browse/SONARJAVA-2735

Thanks for your feedback. 

Cheers

Le ven. 9 mars 2018 à 17:23, Brant Boehmann <brant.b...@gmail.com> a écrit :
I should add that I'm running SonarQube 6.7.1 LTS and SonarJava 5.1.1

On Fri, Mar 9, 2018 at 11:08 AM, Brant Boehmann <brant.b...@gmail.com> wrote:
S1604 raises a false positive when an anonymous inner class calls a default method. Converting to a lambda would cause a compile error because the lambda has a lack of knowledge about "this" and thus cannot call a default method.
I tried to file a ticket in Jira, but could not find a "New Issue" button. I'm assuming I don't have permissions or I overlooked it.

public class SonarTest {

    interface MyFunctional {
        default String defaultMethod() {
            return "defaultMethod";
        }

        String funcMethod();
    }

    public static void main(String[] args) {

        MyFunctional func = new MyFunctional() { //S1604 FP raised here
            @Override
            public String funcMethod() {
                return defaultMethod();
            }
        };

        System.out.println(func.funcMethod());

    }
}


--
You received this message because you are subscribed to a topic in the Google Groups "SonarQube" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sonarqube/a9a5-UfTZZ4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sonarqube+...@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/CAGdygTqZbjLbmiOTWvQ0Y3jh7kTWuoCVAvcBi-5A8wrfKGSLbw%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.
--
Nicolas Peru | SonarSource
Reply all
Reply to author
Forward
0 new messages