hedzr / android-file-chooser

a lightweight file/folder chooser or picker
Apache License 2.0
284 stars 62 forks source link

Crash on runtime (Android 4.2) #69

Closed lupaulus closed 4 years ago

lupaulus commented 5 years ago

This runtime exception append on monkey test of my app that implements the file chooser

The specs

Build Label: Android/NX8/NX8:4.2.2/JDQ39/88.07.20170207:user/release-keys

The events :Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;component=com.sdmo_quiniou/.MainActivity;end // Allowing start of Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.sdmo_quiniou/.MainActivity } in package com.sdmo_quiniou

:Sending Touch (ACTION_DOWN): 0:(283.0,477.0) :Sending Touch (ACTION_UP): 0:(284.1647,469.472) :Sending Trackball (ACTION_MOVE): 0:(3.0,2.0)

// CRASH: com.sdmo_quiniou (pid 2034) // Short Msg: java.lang.NullPointerException // Long Msg: java.lang.NullPointerException

//      at com.obsez.android.lib.filechooser.keyListener.onKey(keyListener.java:48)
//      at android.app.Dialog.dispatchKeyEvent(Dialog.java:703)
//      at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1847)
//      at android.view.ViewRootImpl.deliverKeyEventPostIme(ViewRootImpl.java:3716)
//      at android.view.ViewRootImpl.deliverKeyEvent(ViewRootImpl.java:3641)
//      at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3163)
//      at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4345)
//      at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4324)
//      at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4416)
//      at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:179)
//      at android.os.MessageQueue.nativePollOnce(Native Method)
//      at android.os.MessageQueue.next(MessageQueue.java:125)
//      at android.os.Looper.loop(Looper.java:124)
//      at android.app.ActivityThread.main(ActivityThread.java:5041)
//      at java.lang.reflect.Method.invokeNative(Native Method)
//      at java.lang.reflect.Method.invoke(Method.java:511)
//      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
//      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
//      at dalvik.system.NativeStart.main(Native Method)
hedzr commented 5 years ago

@lupaulus Thanks for your report. I tried on emulator but can't reproduce it. Could you give us more details so that fixing it.

At line 48 of our master, it is:

                    if (_c.get()._neutralBtn.hasFocus() || _c.get()._negativeBtn.hasFocus()

_neutralBtn is null or _negativeBtn? _c.get() is always valid because you'd entered _keyListener.

lupaulus commented 5 years ago

The code I use to call the file chooser

new ChooserDialog(AddArbreActivity.this)
                    .withStartFile(Environment.getExternalStoragePublicDirectory(Environment.getExternalStorageState()).getAbsolutePath())
                    .withChosenListener(new ChooserDialog.Result() {
                        @Override
                        public void onChoosePath(String path, File pathFile) {
                            ouvertureXML(pathFile);
                        }
                    }).build()
                    .show();

I reproduce the bug with

:Sending Touch (ACTION_DOWN): 0:(330.0,787.0)
:Sending Touch (ACTION_UP): 0:(354.7708,791.0)
:Sending Trackball (ACTION_MOVE): 0:(-4.0,-1.0)
:Sending Trackball (ACTION_MOVE): 0:(1.0,-3.0)
:Sending Touch (ACTION_DOWN): 0:(4.0,66.0)

I will show you the result of the keyListener

lupaulus commented 5 years ago

The _c.get().neutralBtn.hasFocus() is null and _c.get().negativeBtn.hasFocus() is null too.

Screen

Guiorgy commented 5 years ago

Either the listener is called before the dialog is even built, but I doubt, or we are loosing our reference to ChooserDialog. _c is a WeakReference after all

@lupaulus, do you get this problem in the older versions? (like 1.1.16)

hedzr commented 5 years ago

I tried and caught one in debug mode. but I have no idea because the afc is entering a strange state: any members are uninitialized or unspecified. I have a suppose about your monkey test: it's so fast so causing some reentering condition? I could add the defensive lines before line 48:

                    if (_c.get()._neutralBtn == null) {
                        return false;
                    }

But I'm afraid that might not really solve the crash matter. Anyway, I'll push a patch to devel including the codes I just said later. Hope works.

lupaulus commented 5 years ago

It's seems it's "human proof" but not "monkey test proof"

I hope my issue have helped you and I will thank you for your project because it's very complete and practical

lupaulus commented 5 years ago

Either the listener is called before the dialog is even built, but I doubt, or we are loosing our reference to ChooserDialog. _c is a WeakReference after all

@lupaulus, do you get this problem in the older versions? (like 1.1.16)

I will test tomorrow with an older version, I haven't tried yet.

lupaulus commented 5 years ago

Hey, hope it can help. On the 1.1.16 at the place of running an exception it shows an toast.

Image

But it seems stable

Guiorgy commented 5 years ago

So it worked right. try the devel-69 branch:

dependencies {
    implementation 'com.github.hedzr:android-file-chooser:devel-69-SNAPSHOT'
}
lupaulus commented 5 years ago

Seems working (monkey test pass)

Guiorgy commented 5 years ago

ok, thanks for the assistance!