Then tell us:
- What language is this for? Kotlin ( java interop )
- Which rule? kotlin:S6518
- SonarQube Server / Community Build - Developer Edition v2025.6.1 (117629)
- How can we reproduce the problem? Give us a self-contained snippet of code
Given the following Java class definition
package sandbox;
public class UserId {
private final String value;
public UserId(String value) {
this.value = value;
}
public String get() {
return value;
}
}
and the following kotlin code
package sandbox
data class User(val id: UserId, val name: String)
interface UserRepository {
fun findById(id: String): User?
fun save(user: User): User?
}
class UserService(val repository: UserRepository) {
fun updateUserName(userId: UserId, newName: String) {
// The call to .get() below wrongly triggers kotlin:S6518
repository.findById(userId.get())?.let { // <====== HERE
repository.save(it.copy(name = newName))
} ?: throw IllegalStateException(
"User with id $userId not found",
)
}
}
the rule should not be triggered yet it is triggered both in sonar and in sonar lint in Intellij