kotlin:S6518 false positive accessing non property get method

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

Hi Jean,

Thanks for the report and the reproducer. I was able to confirm this issue under certain conditions. The good news is that we are already working on a fix for this issue and will release a fix within the near future.

1 Like

thank you !