Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

通过@FilterValue获取(Int/String)的参数时出现(NullPointerException/BindException)异常 #895

Closed
Raven-Book opened this issue Jul 31, 2024 · 1 comment · Fixed by #896
Assignees
Labels
模块:核心 核心与api模块相关的 缺陷 一些存在不影响正常结果的缺陷

Comments

@Raven-Book
Copy link

是否会提供贡献?

版本号

4.3.1

附加版本

simbot-component-onebot-v11-core:1.0.1

涉及的编程语言

Kotlin

项目构建工具

Gradle

涉及的组件库

OneBot

问题描述

e.g. (?<age>\\d+)?

age 被标记为为可选的 name group 时,无法通过 @FilterValue 获取除去 String 以外其他类型。

复现方式

测试一

    @Listener
    @Filter("^test_1(\\s+(?<page>\\d+))?")
    suspend fun OneBotNormalGroupMessageEvent.test1(
        @FilterValue("page", false) page: Int = 1
    ) {
        println("[TEST-1] plain_text->'${messageContent.plainText}' ,page->$page")
    }

测试一: 输入与输出

输入test_1 1

[TEST-1] plain_text->'test_1 1' ,page->1

输入test_1

java.lang.IllegalArgumentException: java.lang.NullPointerException: Cannot invoke "java.lang.Number.intValue()" because the return value of "sun.invoke.util.ValueConversions.primitiveConversion(sun.invoke.util.Wrapper, Object, boolean)" is null

测试二

    @Listener
    @Filter("^test_2(\\s+(?<page>\\d+))?")
    suspend fun OneBotNormalGroupMessageEvent.test2(
        @FilterValue("page") page: String?
    ) {
        println("[TEST-2] plain_text->'${messageContent.plainText}' ,page->$page")
    }

测试二: 输入与输出

输入test_2 1

[TEST-2] plain_text->'test_2 1' ,page->1

输入test_2

love.forte.simbot.quantcat.common.binder.BindException: love.forte.simbot.quantcat.common.binder.BindException: Nothing binder success for listener KFunctionEventListener(caller=fun <packgae_name>.TestListeners.(love.forte.simbot.component.onebot.v11.core.event.message.OneBotNormalGroupMessageEvent.)test2(kotlin.String?): kotlin.Unit, attributes={Attribute(name=$$RAW_LISTEN_TARGET$)=class love.forte.simbot.component.onebot.v11.core.event.message.OneBotNormalGroupMessageEvent, Attribute(name=$$RAW_FUNCTION$)=fun <packgae_name>.TestListeners

/**
 * 指定一个参数,此参数为通过 [love.forte.simbot.quantcat.annotations.Filter]
 * 解析而得到的动态参数提取器中的内容。
 *
 * 参数提取格式基于正则匹配模式,参考 [Filter.value] 中的相关说明。
 *
 * @param value 所需动态参数的key。
 * @param required 对于参数绑定器来讲其是否为必须的。
 *  如果不是必须的,则在无法获取参数后传递null作为结果,否则将会抛出异常并交由后续绑定器处理。
 */

如果不是必须的,则在无法获取参数后传递null作为结果”,也就是说在无法获取时是默认返回空值?

测试三(正常运行)

    @Listener
    @Filter("^test_3(\\s+(?<page>\\d+))?")
    suspend fun OneBotNormalGroupMessageEvent.test3(
        @FilterValue("page") page: String? = null
    ) {
        println("[TEST-3] plain_text->'${messageContent.plainText}' ,page->$page")
    }

测试三:输入与输出

  • 输入 test-3 ,输出 [TEST-3] plain_text->'test_3' ,page->null
  • 输入 test_3 1 , 输出 [TEST-3] plain_text->'test_3 1' ,page->1

相关日志

java.lang.IllegalArgumentException: java.lang.NullPointerException: Cannot invoke "java.lang.Number.intValue()" because the return value of "sun.invoke.util.ValueConversions.primitiveConversion(sun.invoke.util.Wrapper, Object, boolean)" is null
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:113) ~[na:na]
	at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[na:na]
	at kotlin.reflect.jvm.internal.calls.CallerImpl$Method.callMethod(CallerImpl.kt:97) ~[kotlin-reflect-2.0.0.jar:2.0.0-release-341]
	at kotlin.reflect.jvm.internal.calls.CallerImpl$Method$Instance.call(CallerImpl.kt:113) ~[kotlin-reflect-2.0.0.jar:2.0.0-release-341]
	at kotlin.reflect.jvm.internal.KCallableImpl.callDefaultMethod$kotlin_reflection(KCallableImpl.kt:207) ~[kotlin-reflect-2.0.0.jar:2.0.0-release-341]
	at kotlin.reflect.full.KCallables.callSuspendBy(KCallables.kt:74) ~[kotlin-reflect-2.0.0.jar:2.0.0-release-341]
	at love.forte.simbot.quantcat.common.binder.FunctionalBindableEventListener$1.invokeSuspend(FunctionalBindableEventListener.kt:106) ~[simbot-quantcat-common-jvm-4.3.1.jar:na]
	at love.forte.simbot.quantcat.common.binder.FunctionalBindableEventListener$1.invoke(FunctionalBindableEventListener.kt) ~[simbot-quantcat-common-jvm-4.3.1.jar:na]
	at love.forte.simbot.quantcat.common.binder.FunctionalBindableEventListener$1.invoke(FunctionalBindableEventListener.kt) ~[simbot-quantcat-common-jvm-4.3.1.jar:na]
	at love.forte.simbot.quantcat.common.binder.FunctionalBindableEventListener.handle$suspendImpl(FunctionalBindableEventListener.kt:145) ~[simbot-quantcat-common-jvm-4.3.1.jar:na]
	at love.forte.simbot.quantcat.common.binder.FunctionalBindableEventListener.handle(FunctionalBindableEventListener.kt) ~[simbot-quantcat-common-jvm-4.3.1.jar:na]
	at love.forte.simbot.event.EventListeners__EventListenerKt.handleWith(EventListener.kt:56) ~[simbot-api-jvm-4.3.1.jar:na]
	at love.forte.simbot.event.EventListeners.handleWith(Unknown Source) ~[simbot-api-jvm-4.3.1.jar:na]
	at love.forte.simbot.core.event.impl.SimpleEventListenerInvoker.invoke(SimpleEventDispatcherImpl.kt:406) ~[simbot-core-jvm-4.3.1.jar:na]
	at love.forte.simbot.core.event.impl.SimpleEventDispatcherImpl.invokeAndCollectedOrErrorResult(SimpleEventDispatcherImpl.kt:359) ~[simbot-core-jvm-4.3.1.jar:na]
	at love.forte.simbot.core.event.impl.SimpleEventDispatcherImpl.dispatchInFlow(SimpleEventDispatcherImpl.kt:369) ~[simbot-core-jvm-4.3.1.jar:na]
	at love.forte.simbot.core.event.impl.SimpleEventDispatcherImpl.access$dispatchInFlow(SimpleEventDispatcherImpl.kt:269) ~[simbot-core-jvm-4.3.1.jar:na]
	at love.forte.simbot.core.event.impl.SimpleEventDispatcherImpl$eventFlow$flow$1.invokeSuspend(SimpleEventDispatcherImpl.kt:340) ~[simbot-core-jvm-4.3.1.jar:na]
	at love.forte.simbot.core.event.impl.SimpleEventDispatcherImpl$eventFlow$flow$1.invoke(SimpleEventDispatcherImpl.kt) ~[simbot-core-jvm-4.3.1.jar:na]
	at love.forte.simbot.core.event.impl.SimpleEventDispatcherImpl$eventFlow$flow$1.invoke(SimpleEventDispatcherImpl.kt) ~[simbot-core-jvm-4.3.1.jar:na]
	at kotlinx.coroutines.flow.SafeFlow.collectSafely(Builders.kt:57) ~[kotlinx-coroutines-core-jvm-1.8.1.jar:na]
	at kotlinx.coroutines.flow.AbstractFlow.collect(Flow.kt:226) ~[kotlinx-coroutines-core-jvm-1.8.1.jar:na]
	at kotlinx.coroutines.flow.FlowKt__TransformKt$onEach$$inlined$unsafeTransform$1.collect(SafeCollector.common.kt:112) ~[kotlinx-coroutines-core-jvm-1.8.1.jar:na]
	at kotlinx.coroutines.flow.FlowKt__CollectKt.collect(Collect.kt:26) ~[kotlinx-coroutines-core-jvm-1.8.1.jar:na]
	at kotlinx.coroutines.flow.FlowKt.collect(Unknown Source) ~[kotlinx-coroutines-core-jvm-1.8.1.jar:na]
	at kotlinx.coroutines.flow.FlowKt__CollectKt$launchIn$1.invokeSuspend(Collect.kt:46) ~[kotlinx-coroutines-core-jvm-1.8.1.jar:na]
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) ~[kotlin-stdlib-2.0.0.jar:2.0.0-release-341]
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104) ~[kotlinx-coroutines-core-jvm-1.8.1.jar:na]
	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584) ~[kotlinx-coroutines-core-jvm-1.8.1.jar:na]
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:811) ~[kotlinx-coroutines-core-jvm-1.8.1.jar:na]
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:715) ~[kotlinx-coroutines-core-jvm-1.8.1.jar:na]
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:702) ~[kotlinx-coroutines-core-jvm-1.8.1.jar:na]
Caused by: java.lang.NullPointerException: Cannot invoke "java.lang.Number.intValue()" because the return value of "sun.invoke.util.ValueConversions.primitiveConversion(sun.invoke.util.Wrapper, Object, boolean)" is null
	at java.base/sun.invoke.util.ValueConversions.unboxInteger(ValueConversions.java:81) ~[na:na]
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[na:na]
	... 31 common frames omitted

love.forte.simbot.quantcat.common.binder.BindException: love.forte.simbot.quantcat.common.binder.BindException: Nothing binder success for listener KFunctionEventListener(caller=fun <packgae_name>.TestListeners.(love.forte.simbot.component.onebot.v11.core.event.message.OneBotNormalGroupMessageEvent.)test2(kotlin.String?): kotlin.Unit, attributes={Attribute(name=$$RAW_LISTEN_TARGET$)=class love.forte.simbot.component.onebot.v11.core.event.message.OneBotNormalGroupMessageEvent, Attribute(name=$$RAW_FUNCTION$)=fun <packgae_name>.TestListeners.(love.forte.simbot.component.onebot.v11.core.event.message.OneBotNormalGroupMessageEvent.)test2(kotlin.String?): kotlin.Unit, Attribute(name=$listener.keywordList)=[love.forte.simbot.quantcat.common.keyword.SimpleKeyword@4b99a288], Attribute(name=$$RAW_BINDERS$)=[EmptyBinder(parameter=instance parameter of fun <packgae_name>.TestListeners.(love.forte.simbot.component.onebot.v11.core.event.message.OneBotNormalGroupMessageEvent.)test2(kotlin.String?): kotlin.Unit), love.forte.simbot.quantcat.common.binder.impl.MergedBinder@7a02d604, love.forte.simbot.quantcat.common.binder.impl.MergedBinder@58d3e2ce]})
	at love.forte.simbot.quantcat.common.binder.FunctionalBindableEventListener$3.invokeSuspend(FunctionalBindableEventListener.kt:253) ~[simbot-quantcat-common-jvm-4.3.1.jar:na]
	at love.forte.simbot.quantcat.common.binder.FunctionalBindableEventListener$3.invoke(FunctionalBindableEventListener.kt) ~[simbot-quantcat-common-jvm-4.3.1.jar:na]
	at love.forte.simbot.quantcat.common.binder.FunctionalBindableEventListener$3.invoke(FunctionalBindableEventListener.kt) ~[simbot-quantcat-common-jvm-4.3.1.jar:na]
	at love.forte.simbot.quantcat.common.binder.FunctionalBindableEventListener.handle$suspendImpl(FunctionalBindableEventListener.kt:145) ~[simbot-quantcat-common-jvm-4.3.1.jar:na]
	at love.forte.simbot.quantcat.common.binder.FunctionalBindableEventListener.handle(FunctionalBindableEventListener.kt) ~[simbot-quantcat-common-jvm-4.3.1.jar:na]
	at love.forte.simbot.event.EventListeners__EventListenerKt.handleWith(EventListener.kt:56) ~[simbot-api-jvm-4.3.1.jar:na]
	at love.forte.simbot.event.EventListeners.handleWith(Unknown Source) ~[simbot-api-jvm-4.3.1.jar:na]
	at love.forte.simbot.core.event.impl.SimpleEventListenerInvoker.invoke(SimpleEventDispatcherImpl.kt:406) ~[simbot-core-jvm-4.3.1.jar:na]
	at love.forte.simbot.core.event.impl.SimpleEventDispatcherImpl.invokeAndCollectedOrErrorResult(SimpleEventDispatcherImpl.kt:359) ~[simbot-core-jvm-4.3.1.jar:na]
	at love.forte.simbot.core.event.impl.SimpleEventDispatcherImpl.dispatchInFlow(SimpleEventDispatcherImpl.kt:369) ~[simbot-core-jvm-4.3.1.jar:na]
	at love.forte.simbot.core.event.impl.SimpleEventDispatcherImpl.access$dispatchInFlow(SimpleEventDispatcherImpl.kt:269) ~[simbot-core-jvm-4.3.1.jar:na]
	at love.forte.simbot.core.event.impl.SimpleEventDispatcherImpl$eventFlow$flow$1.invokeSuspend(SimpleEventDispatcherImpl.kt:340) ~[simbot-core-jvm-4.3.1.jar:na]
	at love.forte.simbot.core.event.impl.SimpleEventDispatcherImpl$eventFlow$flow$1.invoke(SimpleEventDispatcherImpl.kt) ~[simbot-core-jvm-4.3.1.jar:na]
	at love.forte.simbot.core.event.impl.SimpleEventDispatcherImpl$eventFlow$flow$1.invoke(SimpleEventDispatcherImpl.kt) ~[simbot-core-jvm-4.3.1.jar:na]
	at kotlinx.coroutines.flow.SafeFlow.collectSafely(Builders.kt:57) ~[kotlinx-coroutines-core-jvm-1.8.1.jar:na]
	at kotlinx.coroutines.flow.AbstractFlow.collect(Flow.kt:226) ~[kotlinx-coroutines-core-jvm-1.8.1.jar:na]
	at kotlinx.coroutines.flow.FlowKt__TransformKt$onEach$$inlined$unsafeTransform$1.collect(SafeCollector.common.kt:112) ~[kotlinx-coroutines-core-jvm-1.8.1.jar:na]
	at kotlinx.coroutines.flow.FlowKt__CollectKt.collect(Collect.kt:26) ~[kotlinx-coroutines-core-jvm-1.8.1.jar:na]
	at kotlinx.coroutines.flow.FlowKt.collect(Unknown Source) ~[kotlinx-coroutines-core-jvm-1.8.1.jar:na]
	at kotlinx.coroutines.flow.FlowKt__CollectKt$launchIn$1.invokeSuspend(Collect.kt:46) ~[kotlinx-coroutines-core-jvm-1.8.1.jar:na]
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) ~[kotlin-stdlib-2.0.0.jar:2.0.0-release-341]
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104) ~[kotlinx-coroutines-core-jvm-1.8.1.jar:na]
	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584) ~[kotlinx-coroutines-core-jvm-1.8.1.jar:na]
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:811) ~[kotlinx-coroutines-core-jvm-1.8.1.jar:na]
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:715) ~[kotlinx-coroutines-core-jvm-1.8.1.jar:na]
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:702) ~[kotlinx-coroutines-core-jvm-1.8.1.jar:na]
Caused by: love.forte.simbot.quantcat.common.binder.BindException: Nothing binder success for listener KFunctionEventListener(caller=fun <packgae_name>.TestListeners.(love.forte.simbot.component.onebot.v11.core.event.message.OneBotNormalGroupMessageEvent.)test2(kotlin.String?): kotlin.Unit, attributes={Attribute(name=$$RAW_LISTEN_TARGET$)=class love.forte.simbot.component.onebot.v11.core.event.message.OneBotNormalGroupMessageEvent, Attribute(name=$$RAW_FUNCTION$)=fun <packgae_name>.TestListeners.(love.forte.simbot.component.onebot.v11.core.event.message.OneBotNormalGroupMessageEvent.)test2(kotlin.String?): kotlin.Unit, Attribute(name=$listener.keywordList)=[love.forte.simbot.quantcat.common.keyword.SimpleKeyword@4b99a288], Attribute(name=$$RAW_BINDERS$)=[EmptyBinder(parameter=instance parameter of fun <packgae_name>.TestListeners.(love.forte.simbot.component.onebot.v11.core.event.message.OneBotNormalGroupMessageEvent.)test2(kotlin.String?): kotlin.Unit), love.forte.simbot.quantcat.common.binder.impl.MergedBinder@7a02d604, love.forte.simbot.quantcat.common.binder.impl.MergedBinder@58d3e2ce]})
	at love.forte.simbot.quantcat.common.binder.impl.MergedBinder.arg-IoAF18A(DefaultBinders.kt:130) ~[simbot-quantcat-common-jvm-4.3.1.jar:na]
	at love.forte.simbot.quantcat.common.binder.FunctionalBindableEventListener$3.invokeSuspend(FunctionalBindableEventListener.kt:249) ~[simbot-quantcat-common-jvm-4.3.1.jar:na]
	... 25 common frames omitted
Caused by: love.forte.simbot.quantcat.common.binder.BindException: No keyword matched successfully.
	at love.forte.simbot.quantcat.common.binder.impl.KeywordBinder$Required.arg-IoAF18A(KeywordBinder.kt:90) ~[simbot-quantcat-common-jvm-4.3.1.jar:na]
	at love.forte.simbot.quantcat.common.binder.impl.MergedBinder.arg_IoAF18A$invoke(DefaultBinders.kt:91) ~[simbot-quantcat-common-jvm-4.3.1.jar:na]
	at love.forte.simbot.quantcat.common.binder.impl.MergedBinder.arg-IoAF18A(DefaultBinders.kt:110) ~[simbot-quantcat-common-jvm-4.3.1.jar:na]
	... 26 common frames omitted

其他补充

No response

@Raven-Book Raven-Book added the bug? 疑似为bug、存在普遍性问题、待确认 label Jul 31, 2024
@ForliyScarlet ForliyScarlet added the 等待确认 等待负责人员的确认 label Jul 31, 2024
@ForteScarlet ForteScarlet added 模块:核心 核心与api模块相关的 缺陷 一些存在不影响正常结果的缺陷 and removed bug? 疑似为bug、存在普遍性问题、待确认 等待确认 等待负责人员的确认 labels Jul 31, 2024
@ForteScarlet
Copy link
Member

ForteScarlet commented Jul 31, 2024

“如果不是必须的,则在无法获取参数后传递null作为结果”

如此所述,当 FilterValue 取不到值且 required = false 时,向下传递 null 是预期内的行为,但是当参数不可为 null、且存在默认值时,理应使用默认值,这应该是下游参数绑定器的缺陷。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
模块:核心 核心与api模块相关的 缺陷 一些存在不影响正常结果的缺陷
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants