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

CodeGenerator does not create @DBusBoundProperty annotated fields properly for types TypeRef ans Struct #257

Closed
tutetaki opened this issue May 17, 2024 · 2 comments

Comments

@tutetaki
Copy link

Hello, I have noted several issues using a 5.0.1-SNAPSHOT (master, commit 5041727) to generate the org.freedesktop.NetworkManager interface with the dbus-java-utils module.

Here are the commands. I set the --propertyMethods argument to use the new annotation @DBusBoundProperty.

mvn exec:java \
   -Dexec.mainClass="org.freedesktop.dbus.utils.generator.InterfaceCodeGenerator" \
   -Dexec.executable="java" \
   -Dexec.args="--system --propertyMethods --outputDir /output org.freedesktop.NetworkManager /org/freedesktop/NetworkManager"

mvn exec:java \
   -Dexec.mainClass="org.freedesktop.dbus.utils.generator.InterfaceCodeGenerator" \
   -Dexec.executable="java" \
   -Dexec.args="--system --propertyMethods --outputDir /output org.freedesktop.NetworkManager /org/freedesktop/NetworkManager/Devices/1"
  1. The generated class AddAndActivateConnection2Tuple uses Variant but does not import it.

  2. The gererated interface NetworkManager has property methods annotated with @DBusBoundProperty.
    However the ones using a TypeRef type are not generated properly. For instance, I get:

    @DBusBoundProperty
    public PropertyDevicesType getDevices();
    
    public static interface PropertyDevicesType extends TypeRef<List<DBusPath>> {
    }

    Whereas the expected should be:

    @DBusBoundProperty(type = PropertyDevicesType.class)
    public List<DBusPath> getDevices();
    
    public static interface PropertyDevicesType extends TypeRef<List<DBusPath>> {
    }

    Attempting to use the first version result in a ClassCastException

    > Task :MainNOK.main()
    24/05/17 10:47:30 INFO transports.TransportBuilder: Using transport dbus-java-transport-native-unixsocket for address unix:path=/var/run/dbus/system_bus_socket
    0 [main] INFO org.freedesktop.dbus.connections.transports.TransportBuilder  - Using transport dbus-java-transport-native-unixsocket for address unix:path=/var/run/dbus/system_bus_socket
    Exception in thread "main" java.lang.ClassCastException: class java.util.ArrayList cannot be cast to class org.freedesktop.NetworkManager$PropertyDevicesType (java.util.ArrayList is in module java.base of loader 'bootstrap'; org.freedesktop.NetworkManager$PropertyDevicesType is in unnamed module of loader 'app')
        at jdk.proxy2/jdk.proxy2.$Proxy6.getDevices(Unknown Source)
        at dev.tutetaki.MainNOK.main(MainNOK.java:25)
    
  3. Similarly, generated interface Device has property methods annotated with @DBusBoundProperty.
    But for the field using a Struct type, I get:

    @DBusBoundProperty
    public PropertyStateReasonStruct getStateReason();

    Whereas the expected should be (I'm not sure about this one. Is the intention to use PropertyStateReasonStruct?):

    @DBusBoundProperty(type = PropertyStateReasonStruct.class)
    public Object[] getStateReason();

    Attempting to use the first version result in a ClassCastException

    24/05/17 11:39:40 INFO transports.TransportBuilder: Using transport dbus-java-transport-native-unixsocket for address unix:path=/var/run/dbus/system_bus_socket
    0 [main] INFO org.freedesktop.dbus.connections.transports.TransportBuilder  - Using transport dbus-java-transport-native-unixsocket for address unix:path=/var/run/dbus/system_bus_socket
    Exception in thread "main" java.lang.ClassCastException: class [Ljava.lang.Object; cannot be cast to class org.freedesktop.networkmanager.PropertyStateReasonStruct ([Ljava.lang.Object; is in module java.base of loader 'bootstrap'; org.freedesktop.networkmanager.PropertyStateReasonStruct is in unnamed module of loader 'app')
       at jdk.proxy2/jdk.proxy2.$Proxy8.getStateReason(Unknown Source)
       at dev.tutetaki.MainOK.main(MainOK.java:42)
    

Here is a sample project to reproduce https://github.com/tutetaki/sample-dbus-object/tree/master

@hypfvieh
Copy link
Owner

I fixed the mentioned issues in the latest commits. Anyway, the InterfaceCodeGenerator is far from being perfect. It's just a helper to get started somehow...

@tutetaki
Copy link
Author

Thank you for fixing the things.

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