osfans / trime

同文安卓輸入法平臺3.x/Android-rime/Rime Input Method Engine for Android
http://osfans.github.io/trime/
GNU General Public License v3.0
3.08k stars 372 forks source link

NullPointerException: Attempt to invoke virtual method 'setPadding' on a null object reference #543

Closed iovxw closed 2 years ago

iovxw commented 2 years ago

Describe the bug 在一些特定情况下 com.osfans.trime.ime.core.Trime.loadBackground 会访问未初始化的变量,造成 trime 崩溃

To Reproduce Steps to reproduce the bug:

onCreateInputView 被调用之前调用 loadBackground,通过如下方法

  1. 使 Trime 处于未初始化状态,有几种方式:
    • 在 Android 任务视图里划掉 Trime(这个具体的行为依赖 ROM 的实现,可能无法稳定复现)
    • 覆盖安装 trime
    • trime 崩溃后
    • 系统重启后
  2. 需要注意的是,使用 App Info 里的强制结束无法达到等同效果
  3. 在这之后不要点击任何输入栏
  4. 打开 Trime,进入 Appearance,点击 Themes 或者 Colors
  5. 随便选一个,或者不选,点 OK
  6. 崩溃

Expected behavior A clear and concise description of what you expected to happen.

Log

java.lang.NullPointerException: Attempt to invoke virtual method 'void com.osfans.trime.ime.keyboard.KeyboardView.setPadding(int, int, int, int)' on a null object reference
 at com.osfans.trime.ime.core.Trime.loadBackground(Trime.java:490)
 at com.osfans.trime.ime.core.Trime.initKeyboard(Trime.java:560)
 at com.osfans.trime.settings.components.ColorPickerDialog.selectColor(ColorPickerDialog.kt:46)
 at com.osfans.trime.settings.components.ColorPickerDialog.lambda-2$lambda-0(ColorPickerDialog.kt:34)
 at com.osfans.trime.settings.components.ColorPickerDialog.$r8$lambda$8oSxrFMJJx1x-pXTOGn1ZF_kUvU(Unknown Source:0)
 at com.osfans.trime.settings.components.ColorPickerDialog$$ExternalSyntheticLambda0.onClick(Unknown Source:2)
 at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:174)
 at android.os.Handler.dispatchMessage(Handler.java:106)
 at android.os.Looper.loop(Looper.java:223)
 at android.app.ActivityThread.main(ActivityThread.java:7664)
 at java.lang.reflect.Method.invoke(Native Method)
 at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

Screenshots If applicable, add screenshots to help explain your problem.

Smartphone (please complete the following information):

Additional context Add any other context about the problem here.

Bambooin commented 2 years ago

close by #544