@Pointcut vs. S1186 & S2325

Hi there,

One of our project has started using AspectJ’s @Pointcut annotation. Eg:

@Pointcut("within(com.package.Service+)")
private void isMyService() {}

Such methods tend to be empty, so naturally Sonar complains about:

  • Methods should not be empty (S1186)
  • “private” methods that don’t access instance data should be “static” (S2325)

I know we have multiple options to deal with this: for S1186 we can add a comment which might anyway help point out what the empty method is for. For S2325 we could simply disable the rule in such cases.

I was wondering however if you have considered handling such AOP cases and ignoring the empty method.
It seems this was done for the “unused methods” rule in the past: https://groups.google.com/forum/#!searchin/sonarqube/pointcut|sort:date/sonarqube/4nJ-8VYOTuo/Tb1AnQC2AAAJ so it would be nice to have the same behavior for other rules affected.

Thanks and cheers,
Sandro

Maybe this should be transfered to “bug/false-positve” category, so sonar-java maintainers could have a look?

1 Like

Hi @sandro-h and sorry for the very long delay,

I can reproduce the problem on SonarQube 8.6.0 for both rules. I’ll create tickets to fix these False Positives.

Cheers,

Here are the tickets: SONARJAVA-3668, SONARJAVA-3669.

Thank you for reporting these false positives!

1 Like

Hi @sandro-h @nixel2007.

I have an update on these two tickets:

Let me know if you have any question or remark.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.