We are facing an issue where Sonar is complaining about unnecessary / useless null checks (kotlin:S6619). As you can see on the small code sample this
can indeed be null
.
The code might be not ideal for sure…
Is Sonar understanding the this
correctly inside Kotlin with
statement? Or is Sonar treating this
as class reference - as it normally would be?
val financials: FinancialsTO? = null
with(financials) {
val isReferenceRequired =
this?.totalAssets?.equals(FinancialTotalAssets.UNDER_20) == true ||
this?.revenues?.equals(FinancialRevenues.UNDER_40) == true ||
this?.ownFunds?.equals(FinancialOwnFunds.UNDER_2) == true
if (this == null)
throw BusinessException(ClientClassificationValidationErrors.FINANCIALS_NOT_FILLED)