NPE when extending SignalListItemFactory in 1.12.0 #212
Labels
No labels
bug
dependencies
documentation
duplicate
enhancement
github_actions
good first issue
help wanted
invalid
java
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
java-gi/java-gi#212
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
When updating to this new version, java-gi tries to register my custom
SignalListItemFactoryclasses.However, it fails to find a memory layout (
Types.getLayout) forSignalListItemFactory(neither a@Layoutmethod nor agetMemoryLayoutmethod exist for it), which causes the automated registration of my classes to fail.This then causes any constructor invocation to fail, since these now use
newGObjectwith my extended class.Stacktrace for the suppressed Exception in
Types.getLayout:Stacktrace for the exception this causes in the constructor plus related logs:
Thanks for logging this issue.
In Java-GI 0.12.0, when you create a subclass of a GObject-derived type in Java (or Kotlin), it will automatically try to register the subclass as a new GType. In the past, this was an explicit action (using
Types.register(MyClass.class)).However, defining a new GType is only possible if the parent class can actually be subclassed in native code. The SignalListItemFactory gtype cannot be subclassed (the struct contents are not available in the gir data; it's even defined as a final type). In Java-GI 0.11.2 you could just create a subclass in Java/Kotlin, while native code would regard it as a normal Gtk.SignalListItemFactory.
I hadn't considered this case, so that's why this is now broken. I will add proper error handling for when a native class cannot be subclassed, to still allow it to be subclassed in Java/Kotlin, without automatically defining a new GType.
It might be cleaner to just make such classes final on the JVM side too.
But thanks for the hint! I can probably design something for my app that doesn't depend on inheritance but is still clean.