hypfvieh / dbus-java

Improved version of java DBus library provided by freedesktop.org (https://dbus.freedesktop.org/doc/dbus-java/)
https://hypfvieh.github.io/dbus-java/
MIT License
180 stars 72 forks source link

Kotlin Interface does not work #233

Closed Doomsdayrs closed 2 months ago

Doomsdayrs commented 1 year ago

I have the following class produced by the auto generator, then converted to Kotlin

package org.freedesktop.portal

@Suppress("FunctionName")
@DBusProperty(
    name = "version",
    type = UInt32::class,
    access = DBusProperty.Access.READ
)
actual interface Account : DBusInterface {

    actual fun GetUserInformation(
        window: String,
        options: Map<String, Variant<*>>,
    ): DBusPath
}

Then I have the same class, but in original java.

package org.freedesktop.portal;

/**
 * Auto-generated class.
 */
//@Suppress("FunctionName")
@DBusProperty(
    name = "version",
    type = UInt32.class,
    access = DBusProperty.Access.READ
)
public interface Account extends DBusInterface {

    DBusPath GetUserInformation(
        String window,
        Map<String, Variant<?>> options
    );
}

Utilizing the classes, we get the following results

Language Result
Kotlin org.freedesktop.dbus.exceptions.FatalDBusException: java.io.EOFException: (1) Underlying transport returned -1
Java No error

What is going on here?

hypfvieh commented 1 year ago

I'm not familiar with Kotlin, so I don't know where to start. Anyway, without further log, the complete stacktrace or even better a working example project, I'm really unable to help.

Doomsdayrs commented 1 year ago

I'm not familiar with Kotlin, so I don't know where to start. Anyway, without further log, the complete stacktrace or even better a working example project, I'm really unable to help.

I'll be able to provide better details shortly~

MMarco94 commented 8 months ago

I think the issue is with the Map definition. When Kotlin code is compiled into Java, Map is assumed to be read-only, so its type parameters are converted into the Java equivalent of Map<K, ? extends V>. So, in this case, the type of the value becomes ? extends org.freedesktop.dbus.types.Variant<?>, which the method recursiveGetDBusType cannot handle properly.

As a workaround, you can use MutableMap instead.