Applicability of squid:S1694 - An abstract class should have both abstract and concrete methods

484 views
Skip to first unread message

gremp...@e-spirit.com

unread,
Nov 7, 2016, 8:24:58 AM11/7/16
to SonarQube
Hi,

I have a question regarding rule squid:S1694 "An abstract class should have both abstract and concrete methods".

The description says: "A class with no abstract methods that was made abstract purely to prevent instantiation should be converted to a concrete class (i.e. remove the abstract keyword) with a private constructor."
But what if the abstract class is extended by another class? In that case the abstract class can not be converted to a class with a private constructor, because the sub class is not able to inherit from it.
Nevertheless the rule raises an issue in this case.

I wonder if the rule should take into account that the abstract class has sub classes. Or if this is no valid use case and inheritance isn't really required at all and I should use e.g. delegation...

What do you think?

Best regards
Tim

Michael Gumowski

unread,
Nov 21, 2016, 11:21:56 AM11/21/16
to gremp...@e-spirit.com, SonarQube
Hello Tim,

Thanks for the feedback and sorry for the delay answering you. As you are not specifying, I'll suppose that you are speaking about the Java Analyzer. 

Unfortunately, you are hitting here a limitation of our current semantic engine. Indeed, it's pretty hard to tell when exploring a file containing an abstract class that some extensions exists in the project. The simpler way to handle the issue would be to simply mark the issue as Won't Fix (or False Positive), as fixing it won't work for your case. Another approach, if you are using java8 and your abstract class only contains methods, would be to change it into an interface with default methods.

Cheers,
Michael

--
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/f9c68712-b743-424f-ad08-30a85514c372%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--

Michael GUMOWSKI | SonarSource
Software Developer @ Language Team
http://sonarsource.com
Reply all
Reply to author
Forward
0 new messages