Calling instance methods inherited from MediaStream triggers stack overflow #291
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#291
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?
I am currently implementing a class which is derived from org.gnome.gtk.MediaStream.
MediaStream itself is marked as abstract, but none of the instance methods are.
Therefore I can call them in my Java Code. I think this should not be possible because
all of these methods have to be override. Otherwise, I can call them and upon doing so trigger
a stack overflow.
java-gi version 0.12.2
Closing this because I couldn't read.
One has to call asParent() instead of super
I just found out, that the issue is still valid because calling
asParent().play()also causes the overflow.This method should probably be abstract.
Thanks for logging these issues, I appreciate the feedback!
GObject-introspection doesn't specify whether a virtual method is abstract or not, and many (but not all) have default implementations.
There is an open issue for this: https://gitlab.gnome.org/GNOME/gobject-introspection/-/issues/411
Using
asParent()should have resolved the stack overflow though. Can you provide a short snippet showing how you useasParent()?Thanks for the quick replies. I am currently building a Subsonic API compatible music player so I am
poking at a lot of functions. The following reliably produces a stack overflow:
I know this snippet is nonsensical but the GTK docs of
MediaStreamaren't great and I just did a bunch of experimentationwith the code.
asParent()sets a flag so that when a virtual method is invoked (from Java), it will call the virtual method of the parent class instead of the overridden method. It affects Java code, not native code.The reproducer results in a stack overflow because:
setPlaying(true)calls the C functiongtk_media_stream_set_playinggtk_media_stream_set_playingcalls the C functiongtk_media_stream_playgtk_media_stream_playcalls the virtual methodplayplayvirtual method points to our Javaplay()method, and we go back to step 1.Crucially, step 4 happens in native code, so it's not affected by the call to
asParent()in Java.I haven't tried it, but I'm very certain that all other Gtk language bindings, and even a C application, would exhibit the same stack overflow in this case.
For a working sample on how to create a GtkMediaStream subclass, see this example.
Thanks, that makes complete sense. Closing this.