Skip to content

Signals with struct type parameters generate invalid Java #304

Closed

Description

@zugaldia

When generating Java code with InterfaceCodeGenerator version 5.2.0 on the https://github.com/flatpak/xdg-desktop-portal/blob/main/data/org.freedesktop.portal.GlobalShortcuts.xml file, the following signal produces incorrect code:

<signal name="ShortcutsChanged">
  <arg type="o" name="session_handle" direction="out"/>
  <annotation name="org.qtproject.QtDBus.QtTypeName.Out1" value="QList&lt;QPair&lt;QString,QVariantMap&gt;&gt;"/>
  <arg type="a(sa{sv})" name="shortcuts" direction="out"/>
</signal>

Problematic generated code:

public static class ShortcutsChanged extends DBusSignal {

    private final DBusPath sessionHandle;
    private final List<org.freedesktop.dbus.Struct<String>, Map<String, Variant<?>>> shortcuts;

    public ShortcutsChanged(String path, DBusPath sessionHandle, List<org.freedesktop.dbus.Struct<String>, Map<String, Variant<?>>> shortcuts) throws DBusException {
            super(path, sessionHandle, shortcuts);        this.sessionHandle = sessionHandle;
            this.shortcuts = shortcuts;
    }

    public DBusPath getSessionHandle() {
        return sessionHandle;
    }

    public List<org.freedesktop.dbus.Struct<String>, Map<String, Variant<?>>> getShortcuts() {
        return shortcuts;
    }

}

Build error:

Execution failed for task ':sdk:compileJava'.
> Compilation failed; see the compiler output below.
  /[redacted]/stargate/sdk/src/main/generated/org/freedesktop/portal/GlobalShortcuts.java:98: error: type Struct does not take parameters
          private final List<org.freedesktop.dbus.Struct<String>, Map<String, Variant<?>>> shortcuts;
                                                        ^

I believe the same type of error happens with https://github.com/flatpak/xdg-desktop-portal/blob/main/data/org.freedesktop.portal.Usb.xml in DeviceEvents.

The exact setup can be seen here (Stargate is a Kotlin library that provides JVM applications with access to XDG Desktop Portals on Linux).

I've seen other generation errors with other XDG Portals related XML files. Opening separate tickets for easier tracking. Related: #302 and #303.

Activity

  1. hypfvieh commented on Mar 15, 2026

    @hypfvieh
    Owner

    This issue and also #302 and #303 should be fixed in next 6.0.0 Snapshot.

  2. zugaldia commented on Mar 15, 2026

    @zugaldia
    Author

    Great, thank you for the quick response! Are you publishing v6 releases or snapshots somewhere that I could use to retest? Maybe I missed it but I don't see anything on the README.

  3. hypfvieh commented on Mar 15, 2026

    @hypfvieh
    Owner

    6.0.0-SNAPSHOT is automatically deployed to Sonatype Snapshot Repository as soon as the build/test action was successfully performed by Github Actions.

    A release of 6.0.0 is not planned yet. If required I may take a look backporting the changes to 5.x if I have some more spare time doing so.

  4. zugaldia commented on Mar 15, 2026

    @zugaldia
    Author

    Understood. I just re-tested with the latest snapshot and I can confirm that #302, #303, and #304 are now resolved and the code correctly builds for all portals 🎉

    The bad news is that I encountered a different small issue on a separate portal (Notifications). I opened a ticket here: #306.

    For a final release we would indeed need a stable 6.0 release but this is not urgent on my side (is there a rough timeline?). I can test meanwhile with snapshots.

  5. hypfvieh commented on Mar 15, 2026

    @hypfvieh
    Owner

    I don't have a real time line. Version 6 is the newst iteration and requires a more recent Java which may causes problems for some projects. The earliest date-range would be end of summer or fall this year - but it can also be later.

    I think I should take some more time to give the InterfaceCodeGenerator a bigger update. The code is a mess, contains duplicated code and definitely needs some attention and clean-up. I'm pretty busy currently so I don't know when I'm able to invest the required time to do so.

  6. zugaldia commented on Mar 17, 2026

    @zugaldia
    Author

    Understood. For Stargate in particular, I believe I found a path forward that lets me take advantage of the V6 code generation fixes while still using V5 for the public API zugaldia/stargate#21. Essentially I only use V6 for code generation with avoidUsingTuple = false. As far as I can tell, the generated code this way is compatible with V5. (I understand this is not ideal, and there might be other changes in the V6 generator in the future that might not be compatible with V5. But for now, I'm committing the generated code so I have some control over future V6 updates.)

  7. zugaldia commented on Mar 17, 2026

    @zugaldia
    Author

    Ah, just one small issue. The v6 generator creates getVersion instead of getversion but then the code would fail at runtime (DBusExecutionException: No such property “Version”). The fix I believe is straightforward, adding @DBusBoundProperty(name = "version") to those methods.

  8. hypfvieh commented on Mar 20, 2026

    @hypfvieh
    Owner

    I refactored the InterfaceCodeGenerator code and added some more tests. It would be great if you can check if this version still has any of your reported issues or has introduced any new issues

  9. zugaldia commented on Mar 21, 2026

    @zugaldia
    Author

    @hypfvieh I just opened a PR zugaldia/stargate#27 and regenerated the bindings using the latest snapshot. That should give you a good sense of the full differences I'm seeing. The build passes, but it still fails at runtime. Looks like in this latest version, the full @DBusBoundProperty(name = "version") is still missing.

  10. hypfvieh commented on Mar 21, 2026

    @hypfvieh
    Owner

    @zugaldia thanks a lot. I checked you changes and saw some issues with indention and with creation of Tuples as well.
    I also fixed the missing "name" attribute in DBusBoundProperty annotation if needed (which is only the case, if property name is different than method name without get/is/set prefix).

    Would be great if you can re-generate your classes.
    I guess that there should only be changes in Tuple classes. The setter Methods arguments now have a better name instead of arg and the field name in setters are prefixed with this. to avoid clashes with argument names.

  11. zugaldia commented on Mar 22, 2026

    @zugaldia
    Author

    @hypfvieh I did 1 more regeneration of the Java bindings now with a10c08c in zugaldia/stargate@23f52cb. I can confirm I see the @DBusBoundProperty annotation now (you will not see it in the PR diff because this is something I manually added). The build passes and I'm able to run the demo app with no apparent issues.

  12. hypfvieh commented on Mar 24, 2026

    @hypfvieh
    Owner

    @zugaldia thanks. I checked the results and I think the new results are much better than the previous results.
    Anyway I was not happy with the indention mistakes and fixed that as well. A final test from your side would be good.

  13. zugaldia commented on Mar 25, 2026

    @zugaldia
    Author

    @hypfvieh Happy to. I just updated zugaldia/stargate#27 to 3b33c7 and regenerated. Like before, the build is passing and I did a quick check of the demo app locally and I didn't see any issues. Indentation is looking good. I do see a couple of @DBusMemberName("XXX") removed which I assume is intentional?

  14. hypfvieh commented on Mar 29, 2026

    @hypfvieh
    Owner

    @zugaldia I checked the removal of @DBusMemberName in the generated code.

    The Method getSerialFromBus does not point the a method but to the field serial in the signal and the getter has to be renamed so it does not collide with getSerial of Message super class.

    The same is true for getPathFromBus - this is a method for field path and is renamed to avoid conflicts with getPath of Message super class.

    The setPathFromBus method is the only method which could be renamed to setPath because there is no setPath on the super class. But for the sake of clarity I would prefer to use the same name for setter and getter. The annotation is also not need in this case because the method is related to the field path, not to a method called on the bus.

  15. zugaldia commented on Mar 30, 2026

    @zugaldia
    Author

    Got it, that makes sense to me, including the get/set consistency naming choice. No concerns then.

  16. hypfvieh commented on Apr 6, 2026

    @hypfvieh
    Owner

    Alright. I'll close the issues. Please create a new ticket if you still have issues.

  17. zugaldia commented on Apr 7, 2026

    @zugaldia
    Author

    👍 Sounds good. I have released Stargate 0.4.0 to test these changes more widely.

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