And a thorough description of the problem / question:
Got S2157 reported on a Cloneable class w/o a clone method. So decided to add the method even if here the default behavior was fine (just a number of boolean fields in the class). I then got the S2185 Simply inherit, which should not then happen on a method that we asked to add specifically and also got S2995 to remove clone method and use some form of factory that seems totally contradictory to S2157.
Just wondering… when you override .clone() do you do so by calling super.clone() or by copying each boolean field - maybe even with some “field?true:false” or similar?
(I’m asking because S2185’s message is “Silly math should not be performed”.)
S2995 seems not related to java at all - maybe a typo?
You could give the inherited .clone() a return-type of your current class,
and an explicit cast to this class. Afterall, that’s what it will always end up
returning. And once it returns a different type than the inherited one,
then the override should make sense also to sonarqube. (at least, that’s
what I’d expect - I haven’t tried it.)
And, given that your own class does implement cloning, you could even
catch superclass’ potential exception and declare this class’ .clone() as
not throwing exceptions.