dbus-java icon indicating copy to clipboard operation
dbus-java copied to clipboard

Kotlin Interface does not work

Open Doomsdayrs opened this issue 2 years ago • 3 comments

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?

Doomsdayrs avatar Sep 06 '23 12:09 Doomsdayrs

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.

hypfvieh avatar Sep 07 '23 05:09 hypfvieh

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~

Doomsdayrs avatar Sep 07 '23 14:09 Doomsdayrs

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.

MMarco94 avatar Jan 06 '24 11:01 MMarco94