[JAVA] 3.10 - FP for S1699 Constructors should only call non-overridable methods

146 views
Skip to first unread message

Robert Kaminski

unread,
Feb 13, 2016, 8:16:33 PM2/13/16
to SonarQube
Hi,
   maybe I am wrong, but I think there is a false-positive for java rule squid:S1699.
   Commented method call is not overridable in this situation but is tagged as an issue.


package rk.test;

public class TTest
{
    private static class A
    {
        void test()
        {
            System.err.println("A TEST");
        }
    }

    private static class B extends A
    {
        B()
        {
            super.test();   // FALSE POSITIVE
            System.err.println("B construct");
        }

        @Override
        void test()
        {
            System.err.println("B TEST");
        }
    }

    public static void main(String[] args)
    {
        B b = new B();
        b.test();
    }
}


Regards
Robert Kamiński

Nicolas Peru

unread,
Feb 15, 2016, 5:24:59 AM2/15/16
to Robert Kaminski, SonarQube
Hi Robert, 

Thanks for feedback and reproducer ! 
This is an horrific construction IMO but I agree that this rule should not raise an issue on it : https://jira.sonarsource.com/browse/SONARJAVA-1545 

Cheers, 



--
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/9aa61970-5d04-4699-aa3b-9656ef0bcda8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Adam Gabryś

unread,
Feb 15, 2016, 8:49:12 AM2/15/16
to Nicolas Peru, Robert Kaminski, SonarQube
Hi,
I don't agree ;) Somebody can create inner class C which extends B and override test() method. Issue should not be raised when class B (or test() method) will be declared as final. 

Regards
   Adam Gabryś


From: nicola...@sonarsource.com
Date: Mon, 15 Feb 2016 10:24:48 +0000
Subject: Re: [JAVA] 3.10 - FP for S1699 Constructors should only call non-overridable methods
To: robkam....@gmail.com; sona...@googlegroups.com

Adam Gabryś

unread,
Feb 15, 2016, 8:52:24 AM2/15/16
to Nicolas Peru, Robert Kaminski, SonarQube
Oh, sorry... I didn't see "super"...


From: adam....@live.com
To: nicola...@sonarsource.com; robkam....@gmail.com; sona...@googlegroups.com
Subject: RE: [JAVA] 3.10 - FP for S1699 Constructors should only call non-overridable methods
Date: Mon, 15 Feb 2016 14:49:08 +0100

Robert Kaminski

unread,
Feb 15, 2016, 7:03:39 PM2/15/16
to SonarQube, robkam....@gmail.com
Hi,
  it's not pretty but useful sometimes. I use it for setting default values in ActiveJDBC tuples.

Regards
Robert Kamiński
Reply all
Reply to author
Forward
0 new messages