libsuperuser icon indicating copy to clipboard operation
libsuperuser copied to clipboard

NullPointerException in onClosed for Threaded Shell

Open JesperLR opened this issue 5 years ago • 2 comments

Hi

We're experiencing a crash, coming from Shell object, that happens sporadically, but on many devices (+100 devices). The crash is seen with the newest version of the lib, i.e. "eu.chainfire:libsuperuser:1.1.0.202004101746"

The stacktrace is as following:

Fatal Exception: java.lang.NullPointerException
Attempt to invoke virtual method 'boolean java.lang.Thread.isAlive()' on a null object reference
eu.chainfire.libsuperuser.Shell$Threaded.onClosed (Shell.java:2884)
eu.chainfire.libsuperuser.Shell$Interactive.runNextCommand (Shell.java:1876)
eu.chainfire.libsuperuser.Shell$Interactive.runNextCommand (Shell.java:1726)
eu.chainfire.libsuperuser.Shell$Interactive.access$3700 (Shell.java:1526)
eu.chainfire.libsuperuser.Shell$Interactive$6.onStreamClosed (Shell.java:2119)
eu.chainfire.libsuperuser.StreamGobbler.run (StreamGobbler.java:169)

Looking at Shell.java:2884 it's obvious that it will produce a nullPointer (possibly in multiple following lines as well) if the handlerThread field variable is null.

Unfortunately I have not been able to reproduce the crash myself. I have also not been able to logically walk through the Shell code to understand how onClosed may be called while handlerThread is still null, or how it could somehow become a null object before the final statement is reached in onClosed. My best guess would therefore be a couple of simple null checks, which I assume would be safe in terms of quitting the thread, as it presumably would not exist or already have been GC in that case.

Any help or possible fix would be greatly appreciated, thanks! :)

JesperLR avatar Aug 12 '20 08:08 JesperLR

what is your kernal?

Kilo-411 avatar Dec 04 '20 21:12 Kilo-411

Hi, I'm not sure how the kernel of the devices that experience this issue are relevant - can you elaborate on that?

JesperLR avatar Dec 06 '20 09:12 JesperLR