Sonar marks classes implementing abstract class as duplicate code

Hello,

I have two classes, XClientSettings and YClientSettings, both implementing an abstract class ClientSettings. They only define constructors, however the code in both classes is marked as duplicate. It’s worth noting that the Strings in the @Value annotations differ inside the reported duplicate block (e.g. "\${XXX.circuitBreaker.maximumAttempts:10}" in XClientSettings class vs "\${YYY.circuitBreaker.maximumAttempts:10}" in YClientSettings class - which in my opinion should disallow them from being considered duplicate.

@Singleton
open class XClientSettings(
        @Value("\${XXX.circuitBreaker.maximumAttempts:10}")
        override val maxAttempts: Int = 10,
        @Value("\${XXX.circuitBreaker.timeout:30}")
        override val timeout: Int = 30,
        @Value("\${XXX.circuitBreaker.expirationTime:300}")
        override val expirationTime: Int = 300,
        @Value("\${XXX.retry.enabled:true}")
        override var retry: Boolean = true
) : ClientSettings() {
        override val serviceName = "X"
}

Is it expected behavior? I’ve disposed of this issue by setting sonar.cpd.exclusions in build.gradle of my project, however I’m not sure whether such examples should be really considered as duplicates. Any suggestions on this issue?

2 Likes

Hello @magnes,

Thanks for your feedback.

To my mind, this example should not be considered as a duplicate.

Could you please clarify what version of SQ you’re using? There were some changes in the Kotlin rules in recent versions. So we need to understand, whether it was introduced recently or was there before.

In the meantime you can mark this exact issue in SQ ui as FP or Won' fix.

Regards,
Margarita

Hi @Margarita_Nedzelska,
Thank you for quick response :slight_smile: We’re using SQ 8.8.

Thanks for your response @magnes

Could you, please update your SQ to 9.0 and check whether the issue still reproduces.

Regards,
Margarita