Skip to content

A Tuple returned by an exported DBusInterface can't be cast to ParameterizedType #271

Closed

Description

@bachrc

Having a DBusInterface that contain multiple fields, generated automatically, like this :

import java.util.List;

import org.freedesktop.dbus.annotations.DBusBoundProperty;
import org.freedesktop.dbus.annotations.DBusInterfaceName;
import org.freedesktop.dbus.exceptions.DBusException;
import org.freedesktop.dbus.interfaces.DBusInterface;
import org.freedesktop.dbus.messages.DBusSignal;
import org.freedesktop.dbus.types.UInt16;
import org.freedesktop.dbus.types.UInt32;

/**
 * Auto-generated class.
 */
@DBusInterfaceName("com.interface.yes")
public interface ModemManager1 extends DBusInterface {

    public void ResetModem();

    GetDetailsTuple GetDetails();
...

And in the generated Tuple:

import org.freedesktop.dbus.Tuple;
import org.freedesktop.dbus.annotations.Position;
import org.freedesktop.dbus.types.UInt16;
import org.freedesktop.dbus.types.UInt64;

/**
 * Auto-generated class.
 */
public class GetDetailsTuple extends Tuple {
    @Position(0)
    private byte info;
    @Position(1)
    private UInt16 field;
...

When I try to export it:

ModemManager1 modemManager = new ModemManagerMock();
            connection.requestBusName("com.interface.yes");
            connection.exportObject(modemManager.getObjectPath(), modemManager);
...

I have the following error:

2024-10-29 17:30:26.342 [com.interface.yes.Main.main()] INFO  o.f.d.c.transports.TransportBuilder - Using transport dbus-java-transport-native-unixsocket for address unix:path=/var/run/dbus/system_bus_socket
java.lang.ClassCastException: class java.lang.Class cannot be cast to class java.lang.reflect.ParameterizedType (java.lang.Class and java.lang.reflect.ParameterizedType are in module java.base of loader 'bootstrap')
        at org.freedesktop.dbus.messages.ExportedObject.generateMethodsXml(ExportedObject.java:235)
        at org.freedesktop.dbus.messages.ExportedObject.generateIntrospectionXml(ExportedObject.java:368)
        at org.freedesktop.dbus.messages.ExportedObject.<init>(ExportedObject.java:43)
        at org.freedesktop.dbus.connections.AbstractConnection.lambda$exportObject$0(AbstractConnection.java:175)
        at org.freedesktop.dbus.connections.base.AbstractConnectionBase.doWithExportedObjects(AbstractConnectionBase.java:333)
        at org.freedesktop.dbus.connections.AbstractConnection.exportObject(AbstractConnection.java:171)
        at com.interface.yes.Main.main(Main.java:31)
        at org.codehaus.mojo.exec.ExecJavaMojo.doMain(ExecJavaMojo.java:385)
        at org.codehaus.mojo.exec.ExecJavaMojo.doExec(ExecJavaMojo.java:374)
        at org.codehaus.mojo.exec.ExecJavaMojo.lambda$execute$0(ExecJavaMojo.java:296)
        at java.base/java.lang.Thread.run(Thread.java:1575)

I do not have the problem when the GetDetailsTuple extends from a Struct.

Activity

  1. added a commit that references this issue on Oct 30, 2024
  2. hypfvieh commented on Oct 30, 2024

    @hypfvieh
    Owner

    This issue should be fixed in the latest commit. Using any Container extending class as return type should not work as expected.

  3. bachrc commented on Oct 30, 2024

    @bachrc
    Author

    Thanks a lot, that was quick!! Until the release of the fix, do you know how I could integrate your latest changes in my maven project?

  4. changed the title [-]An exported DBusInterface having a method returning a Tuple [/-] [+]An Tuple returned by an exported DBusInterface can't be cast to ParameterizedType[/+] on Oct 30, 2024
  5. changed the title [-]An Tuple returned by an exported DBusInterface can't be cast to ParameterizedType[/-] [+]A Tuple returned by an exported DBusInterface can't be cast to ParameterizedType[/+] on Oct 30, 2024
  6. hypfvieh commented on Oct 30, 2024

    @hypfvieh
    Owner

    I only know two options:

    1. Replacing the class by providing a copy of the patched class in the same package in your artifact
    2. Using the latest Snapshot of dbus-java instead of the release version. Snapshots are provided automatically in Maven Central Snapshot Repository whenever I push changes to master branch.

    Variant 1 is more hacky. It requires you to ensure that your artifact is listed before dbus-java in your class path otherwise the patched class will not be loaded.
    This option will also only work when your project is NOT using JPMS (Jigsaw).

    Variant 2 is the more convenient one, but depends on your project policy. If your policy (or your companies policy) is to never use snapshots or pre-releases (alpha or beta versions), you may not use the snapshot.

  7. bachrc commented on Oct 30, 2024

    @bachrc
    Author

    (I'm sorry for being offtopic but I don't know where I can ask you this, I can delete my message afterwards)

    I do not see any snapshot of yours on Maven Central though, could you help me with a link maybe?

  8. hypfvieh commented on Oct 30, 2024

    @hypfvieh
    Owner

    Maven will not use the official snapshot repository by default. You have to enable it either in your Maven settings.xml or in the pom of your project.
    See the first two answers in this Stackoverflow post, depending on the method you want use to enable the snapshot repo.
    This will allow Maven to download the most recent snapshot from here.

  9. bachrc commented on Oct 30, 2024

    @bachrc
    Author

    Again, thanks a lot for your time! I'll be using the SNAPSHOT until the release because your fix works perfectly!

    I will close the issue, thank you for being so reactive, please have a great day

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions