hansemannn / titanium-crashlytics

Use the native Crashlytics SDK in Titanium (iOS / Android).
MIT License
18 stars 18 forks source link

Android: Crash in new integration #40

Closed hansemannn closed 2 years ago

hansemannn commented 3 years ago

The changes from @petenathan42 were great! But unfortunately, we now see some crashes with the following stack trace. It seems like Intercom also influences this.

java.lang.NullPointerException: 
  at java.util.Objects.requireNonNull (Objects.java:245)
  at java.lang.StackTraceElement.<init> (StackTraceElement.java:71)
  at ti.crashlytics.TitaniumCrashlyticsModule.generateStackTrace (TitaniumCrashlyticsModule.java:69)
  at ti.crashlytics.TitaniumCrashlyticsModule$1.handleException (TitaniumCrashlyticsModule.java:117)
  at org.appcelerator.kroll.KrollRuntime.dispatchException (KrollRuntime.java:541)
  at org.appcelerator.titanium.TiApplication$1.uncaughtException (TiApplication.java:333)
  at io.intercom.android.sdk.errorreporting.IntercomExceptionHandler.uncaughtException (IntercomExceptionHandler.java:37)
  at org.appcelerator.kroll.KrollProxy.handleMessage (KrollProxy.java:1256)
  at android.os.Handler.dispatchMessage (Handler.java:102)
  at android.os.Looper.loop (Looper.java:254)
  at android.app.ActivityThread.main (ActivityThread.java:8199)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:612)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1006)
hansemannn commented 3 years ago

Looking at this source, it seems like declaringClass can be null.

petenathan42 commented 3 years ago

I think I over-engineered a part of the implementation.

Instead of:

if (splitByParen[0].indexOf(splitByParen[1].split("\\.")[0]) > -1) {
    declaringClass = splitByParen[0].substring(0, splitByParen[0].indexOf(splitByParen[1].split("\\.")[0]) - 1).trim();
    methodName = splitByParen[0].substring(splitByParen[0].indexOf(splitByParen[1].split("\\.")[0]));
} else {
    declaringClass = splitByParen[0].substring(0, splitByParen[0].lastIndexOf('.')).trim();
    methodName = splitByParen[0].substring(splitByParen[0].lastIndexOf('.') + 1);
}

It really can be just what's in the else:

declaringClass = splitByParen[0].substring(0, splitByParen[0].lastIndexOf('.')).trim();
methodName = splitByParen[0].substring(splitByParen[0].lastIndexOf('.') + 1);

You are going to get the same result in the firebase console either way.

and just for good measure, I will add:

if (declaringClass == null) {
    declaringClass = "unknown";
}
if (methodName == null) {
    methodName = "unknown";
}
petenathan42 commented 3 years ago

fix: https://github.com/hansemannn/titanium-crashlytics/pull/42