obs-websocket-community-projects/obs-websocket-java

compute event subscriptions - fails on custom event

TinaTiel opened this issue · 6 comments

When trying to subscribe with a custom event, it looks like the computation of subscriptions fails with:

java.lang.NoSuchMethodException: io.obswebsocket.community.client.message.event.general.CustomEvent.<init>()

The method itself uses introspection to get the event type of the class...Maybe we could just use the getter?
Would also be a great opportunity to add some unit tests for this feature.

I suspect this happens on other events that extend Event and have a many-argument constructor...there would be no zero-arg constructor.

Trying to think of a clever way to solve this that doesn't involve either declaring a static constructor on all events, or a unique event registration method for each event type...

Also noticed while investigating that we have no tests verifying deserialization of events....Makes it difficult to determine if any breaking changes will be introduced when trying to fix this.

Depending on how this should be fixed, eventType may be a static ref or an instance method...refactoring that would be a PIA.
So, I suggest we start a few tests in this ticket, and then followup with unit tests for events.

Yeah, I knew it would produce some errors but didn't find a better way to handle it at that time

The CustomEvent shouldn't have a Builder and a param in the constructor imo
The object instance is created by Gson when deserialized, not by us
By default Gson uses the no-args constructor to create an instance
There is a way of providing a custom InstanceCreator if we need, but I don't think it should be the case here

@ChristopheCVB I got back from my walk and saw you've created a branch for this issue, so I've assigned it to you.

I see what you mean on CustomEvent's constructor -- taking another look, I think it's the only one like this.
Thanks for taking a look!

CustomEvent has been deleted for now. We need to recreate it