You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm integrating this library into my own project and I'm running across a very bizarre issue that causes an event handler to be registered for all events without me specifying as such.
Specifically, I have a class Foo which is derived from some other class (which doesn't have any "onEvent" methods) which subscribes to events for SomeEnum.
public enum SomeEnum() {
// Nothing fancy
}
public class Foo extends SomeClassWithNoOnEvent {
...
public void onEvent(SomeEnum someEnum) { /* Handler logic */ }
...
}
On the same EventBus, I register another class which has nothing to do with Foo.
public class Bar {
...
public void onEvent(SomeType someType) { /* Handler logic */}
}
When I post an instance of "SomeType", EventBus attempts to invoke Bar (correctly) and Foo's onEvent even though I never signed up for it.
Could not dispatch event: class com.foo.Bar to subscribing class class com.foo.Foo
java.lang.ClassCastException: com.foo.Bar cannot be cast to com.foo.Foo
at com.foo.Foo.onEvent(Foo.java:1)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at de.greenrobot.event.EventBus.invokeSubscriber(EventBus.java:569)
at de.greenrobot.event.EventBus.postToSubscription(EventBus.java:500)
at de.greenrobot.event.EventBus.postSingleEvent(EventBus.java:475)
at de.greenrobot.event.EventBus.post(EventBus.java:365)
at com.foo.SomeClass(SomeClass.java:286)
After stepping through a debugger and researching online I found out some interesting tidbits:
SubscriberMethodFinder.findSubscriberMethods does not skip this invalid function
It shouldn't be difficult to handle this, considering findSubscriberMethods is already using Modifier flags (just need to use Modifier.VOLATILE) in this block:
As a work around, I suspect isolating Foo to it's own EventBus would prevent the nasty logs from showing up. I can follow up with results of that, if need be.
Anyways, this would certainly be a welcome fix for any users experiencing the same problem! 👍
The text was updated successfully, but these errors were encountered:
Hello,
I'm integrating this library into my own project and I'm running across a very bizarre issue that causes an event handler to be registered for all events without me specifying as such.
Specifically, I have a class Foo which is derived from some other class (which doesn't have any "onEvent" methods) which subscribes to events for SomeEnum.
On the same EventBus, I register another class which has nothing to do with Foo.
When I post an instance of "SomeType", EventBus attempts to invoke Bar (correctly) and Foo's onEvent even though I never signed up for it.
After stepping through a debugger and researching online I found out some interesting tidbits:
(http://stackoverflow.com/questions/10370033/java-volatile-in-method-signature, http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6868371 )
It shouldn't be difficult to handle this, considering findSubscriberMethods is already using Modifier flags (just need to use Modifier.VOLATILE) in this block:
As a work around, I suspect isolating Foo to it's own EventBus would prevent the nasty logs from showing up. I can follow up with results of that, if need be.
Anyways, this would certainly be a welcome fix for any users experiencing the same problem! 👍
The text was updated successfully, but these errors were encountered: