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

context 空指针 #208

Closed
hust-twj opened this issue Oct 25, 2024 · 4 comments
Closed

context 空指针 #208

hust-twj opened this issue Oct 25, 2024 · 4 comments
Labels
help wanted Extra attention is needed

Comments

@hust-twj
Copy link

hust-twj commented Oct 25, 2024

我们 APP 跳转的时候,有的场景没有传入 context 参数。

理论上 getApplicationContext() 通过 ContentProvider 初始化后赋值,应该不为 null,但是线上还是上报了少量的空指针。
线上也打印了日志, getApplicationContext() 确实为 null。

目前我的解决方案:

  1. 路由跳转的时候尽量都带上 context
  2. TheRouter 初始化的时候 检查 getApplicationContext() 是不是为null,为 null 则调用 setContext() 。

不过,建议底层的 nagavitor() 方法还是应该兜个底,或者 为 null 的时候直接抛异常,排查问题也会更加方便。

image

image

image

@kymjs
Copy link
Collaborator

kymjs commented Oct 26, 2024

多进程的情况吧,子进程需要手动setContext()

1 similar comment
@kymjs
Copy link
Collaborator

kymjs commented Oct 26, 2024

多进程的情况吧,子进程需要手动setContext()

@hust-twj
Copy link
Author

多进程的情况吧,子进程需要手动setContext()

应该不是,这个问题只有几十个用户出现了,不是必现的,否则就是大面积了,而且路由跳转的地方在主进程。比较困惑..

@kymjs kymjs added the bug bug label Oct 31, 2024
@kymjs
Copy link
Collaborator

kymjs commented Oct 31, 2024

1.2.3-rc5加了逻辑判断,但只能保证release环境不崩溃,debug环境主动抛异常。为空的情况应该还是系统回收了,需要考虑一下怎么避免。

@kymjs kymjs closed this as completed Oct 31, 2024
@kymjs kymjs added help wanted Extra attention is needed and removed bug bug labels Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants