Klitos Kyriacou

04/14/2022, 8:38 AM
I've got an error message that I don't understand:
val sqlServerDataSource = SQLServerDataSource()
        sqlServerDataSource.url = myUrl
        sqlServerDataSource.user = myUser
        sqlServerDataSource.password = myPassword
The error is:
Cannot access 'password': it is public/*package*/ for synthetic extension in '<library Maven:>'
There is no error on url or user; only on password. If I replace it with
it works. But why can't I use the property syntax, and what exactly does the error message mean, and why only password has this error?
It turns out that this seems to be caused by the Java class SQLServerDataSource having
public void setPassword(String password)
but only a package-private
String getPassword()
. This prevents Kotlin from synthesizing a
property. Is this intentional, or is it a bug?

Michael de Kaste

04/14/2022, 9:24 AM
It's definitely a weird visibility way sqlServerDataSource uses since it's literally impossible to recreate the same scenario in kotlin; this the field cannot be mapped properly to kotlin accessibility
so it seems that setPassword and getPassword should be actual functions you should access in kotlin as well. The fact you can directly access a "password" field is a bug I would say


04/14/2022, 9:26 AM
Note that, if the Java class only has a setter, it isn't visible as a property in Kotlin because Kotlin doesn't support set-only properties.
👍 1
:thank-you: 1


04/14/2022, 10:21 AM
the Java functions are always accessible (up to visibility) even when Kotlin synthesizes a property