Can rule ""Optional" should not be used for parameters" be generalized to other classes?

Hello all!

I would like to add a rule to sonar that detects the use of a certain class as a parameter.
I noticed that this exists for Optional, but I would like to extend this rule for other classes as well.

Does someone know if this is possible?
Thanks in advance!


To be clear, we’re talking about Java, right?


Yes indeed, I am talking about java! :slight_smile:

1 Like

Hello @khilgert,

To my knowledge, there is no rule that reports an issue when a given Class is used as a parameter. My feeling is that it would be too broad to be useful, we rather go for more specific rules with clear motivation on why a given class should be avoided (such as the one on Optional).

At this point, do you have a specific list of popular classes in mind that any developer should avoid using as parameter? Or is it something specific to your needs?

In the former case, you could describe them here, and develop why they should be avoided.

In the latter, you can still do this thanks to Custom rules. What you are trying to achieve is not too complex, if you follow this tutorial you will have all the tools to do what you are looking for.

Hope this helps.


1 Like