While trying to install a custom exception handler to catch uncaught exceptions (crashes), I ended up writing

Java
1
2
CustomExceptionHandler handler = new CustomExceptionHandler(Thread.currentThread().getUncaughtExceptionHandler());
Thread.setDefaultUncaughtExceptionHandler(handler);

instead of

Java
1
2
3
Thread.UncaughtExceptionHandler existingHandler = Thread.getDefaultUncaughtExceptionHandler();
CustomExceptionHandler handler = new CustomExceptionHandler(existingHandler);
Thread.setDefaultUncaughtExceptionHandler(handler);

The difference looks minor but it broke the exception handler and converted every crash into a cryptic ANR!

C
1
2
3
4
5
6
7
0 libc.so syscall
1 libart.so art::ConditionVariable::WaitHoldingLocks(art::Thread*)
2 libart.so art::ThreadList::WaitForOtherNonDaemonThreadsToExit(bool)
3 libart.so art::JII::DestroyJavaVM(_JavaVM*)
4 libandroid_runtime.so android::AndroidRuntime::start(char const*, android::Vector const&, bool)
5 app_process64 main
6 libc.so __libc_init

Very occasionally, I got a more useful error that didn’t look related but it was.

Java
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
java.lang.StackOverflowError:
      at net.ashishb.androidmusicplayer.util.CustomExceptionHandler.uncaughtException (CustomExceptionHandler.java:20)
      at java.lang.ThreadGroup.uncaughtException (ThreadGroup.java:1068)
      at java.lang.ThreadGroup.uncaughtException (ThreadGroup.java:1063)
      at net.ashishb.androidmusicplayer.util.CustomExceptionHandler.uncaughtException (CustomExceptionHandler.java:22)
      at org.chromium.base.JavaExceptionReporter.uncaughtException (chromium-Monochrome.aab-stable-484407323:6)
      at java.lang.ThreadGroup.uncaughtException (ThreadGroup.java:1068)
      at java.lang.ThreadGroup.uncaughtException (ThreadGroup.java:1063)
      at net.ashishb.androidmusicplayer.util.CustomExceptionHandler.uncaughtException (CustomExceptionHandler.java:22)
      at org.chromium.base.JavaExceptionReporter.uncaughtException (chromium-Monochrome.aab-stable-484407323:6)
      at java.lang.ThreadGroup.uncaughtException (ThreadGroup.java:1068)
      at java.lang.ThreadGroup.uncaughtException (ThreadGroup.java:1063)
      at net.ashishb.androidmusicplayer.util.CustomExceptionHandler.uncaughtException (CustomExceptionHandler.java:22)
      at org.chromium.base.JavaExceptionReporter.uncaughtException (chromium-Monochrome.aab-stable-484407323:6)