Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
bachrc opened this issue Oct 29, 2024 · 6 comments

Comments

@bachrc
Copy link

bachrc commented Oct 29, 2024

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.

hypfvieh added a commit that referenced this issue Oct 30, 2024
@hypfvieh
Copy link
Owner

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

@bachrc
Copy link
Author

bachrc commented Oct 30, 2024

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?

@bachrc bachrc 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 Oct 30, 2024
@bachrc bachrc 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 Oct 30, 2024
@hypfvieh
Copy link
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.

@bachrc
Copy link
Author

bachrc commented Oct 30, 2024

(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?

@hypfvieh
Copy link
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.

@bachrc
Copy link
Author

bachrc commented Oct 30, 2024

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

@bachrc bachrc closed this as completed Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants