Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

squid:MaximumInheritanceDepth on Android

Tags:

java

sonarqube

This is my setup:

  • SonarQube 5.6.6
  • SonarJava plugin 4.8.0.9441

Code:

public class BaseActivity extends android.app.Activity {}

public class FooActivity extends BaseActivity {}

SonarQube thinks that FooActivity violates squid:MaximumInheritanceDepth:

This class has 6 parents which is greater than 5 authorized.

android.app.Activity is Android Native API. Shouldn't any super classes of Activity be ignored when calculating violations for this rule?

Is this a bug?

like image 416
Alix Avatar asked Apr 27 '17 09:04

Alix


1 Answers

This is not a bug, but rather a configuration issue. Rule squid:S110 can be configured to filter out classes from the inheritance tree. By default, no class is ignored and the rule simply count the number of inheritance levels till reaching Object class. In order to configure filtered classes, you have to set up the filteredClasses rule property.

Note that it is plan to update to rule to not simply exclude filtered classes from the total inheritance depth, but stop incrementing inheritance levels as soon as reaching a filtered class. The fix will be done when handling Jira ticket SONARJAVA-2252.

like image 98
Wohops Avatar answered Nov 08 '22 18:11

Wohops