Skip to content

fix: Lambda creation failed, fallback to parent's reflection implemen…#4012

Open
xihan123 wants to merge 3 commits intoalibaba:mainfrom
xihan123:main
Open

fix: Lambda creation failed, fallback to parent's reflection implemen…#4012
xihan123 wants to merge 3 commits intoalibaba:mainfrom
xihan123:main

Conversation

@xihan123
Copy link
Copy Markdown

@xihan123 xihan123 commented Mar 7, 2026

What this PR does / why we need it?

修复 Android 环境下使用 JSON.parseObject、JSON.toJSONString 等方法时抛出的 NullPointerException。

在 Android 平台上,MethodHandles.Lookup.in() 方法可能返回 null,导致 Lambda 创建失败并抛出异常。此 PR 使 PropertyAccessorFactoryLambda 在 Lambda
创建失败时能够回退到父类的反射实现,而不是直接抛出异常导致程序崩溃。

Fixes #4011

Summary of your change

修改 PropertyAccessorFactoryLambda.create() 方法,在 Lambda 创建逻辑外层添加 try-catch 块。当 Lambda 创建失败(抛出 Throwable)时,捕获异常并忽略,然后继续执行到最后的
return super.create(...) 语句,回退到父类的反射实现。

Please indicate you've done the following:

  • Made sure tests are passing and test coverage is added if needed.
  • Made sure commit message follow the rule of Conventional Commits specification.
  • Considered the docs impact and opened a new docs issue or PR with docs changes if needed.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 7, 2026

CLA assistant check
All committers have signed the CLA.

@wenshao
Copy link
Copy Markdown
Member

wenshao commented Mar 10, 2026

单测跑不过,merge from main分支试下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] NullPointerException: java.lang.invoke.MethodHandles$Lookup java.lang.invoke.MethodHandles$Lookup.in(java.lang.Class)

3 participants