diff --git a/java-test/src/test/java/net/mamoe/mirai/javatest/SimpleListenerHostTest.java b/java-test/src/test/java/net/mamoe/mirai/javatest/SimpleListenerHostTest.java index 80efb08ae..422e925ba 100644 --- a/java-test/src/test/java/net/mamoe/mirai/javatest/SimpleListenerHostTest.java +++ b/java-test/src/test/java/net/mamoe/mirai/javatest/SimpleListenerHostTest.java @@ -8,33 +8,33 @@ package net.mamoe.mirai.javatest; -import kotlin.coroutines.CoroutineContext; import kotlin.coroutines.EmptyCoroutineContext; import kotlinx.coroutines.CoroutineScope; import kotlinx.coroutines.CoroutineScopeKt; import net.mamoe.mirai.event.*; -import org.jetbrains.annotations.NotNull; import org.junit.Test; +import java.util.concurrent.atomic.AtomicBoolean; + public class SimpleListenerHostTest { @Test - public void test() { + public void testJavaSimpleListenerHostWork() { + AtomicBoolean called = new AtomicBoolean(); final SimpleListenerHost host = new SimpleListenerHost() { @EventHandler public void testListen( AbstractEvent event ) { System.out.println(event); - } - - @Override - public void handleException(@NotNull CoroutineContext context, @NotNull Throwable exception) { - exception.printStackTrace(); + called.set(true); } }; CoroutineScope scope = CoroutineScopeKt.CoroutineScope(EmptyCoroutineContext.INSTANCE); Events.registerEvents(scope, host); EventKt.broadcast(new AbstractEvent() { }); + if (!called.get()) { + throw new AssertionError("JavaTest: SimpleListenerHost Failed."); + } } } diff --git a/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/event/internal/EventInternalJvm.kt b/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/event/internal/EventInternalJvm.kt index 796862ee5..d4ee9663f 100644 --- a/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/event/internal/EventInternalJvm.kt +++ b/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/event/internal/EventInternalJvm.kt @@ -161,11 +161,11 @@ internal fun Method.registerEvent( if (annotation.ignoreCancelled) { if ((this as? CancellableEvent)?.isCancelled != true) { withContext(Dispatchers.IO) { - this@registerEvent.invoke(owner, this) + this@registerEvent.invoke(owner, this@subscribeAlways) } } } else withContext(Dispatchers.IO) { - this@registerEvent.invoke(owner, this) + this@registerEvent.invoke(owner, this@subscribeAlways) } } } @@ -179,11 +179,11 @@ internal fun Method.registerEvent( if (annotation.ignoreCancelled) { if ((this as? CancellableEvent)?.isCancelled != true) { withContext(Dispatchers.IO) { - this@registerEvent.invoke(owner, this) as ListeningStatus + this@registerEvent.invoke(owner, this@subscribe) as ListeningStatus } } else ListeningStatus.LISTENING } else withContext(Dispatchers.IO) { - this@registerEvent.invoke(owner, this) as ListeningStatus + this@registerEvent.invoke(owner, this@subscribe) as ListeningStatus } }