hey folks, I get some weird NullPointerException t...
# android
j
hey folks, I get some weird NullPointerException that happens just a few times on prod...
Copy code
Caused by java.lang.NullPointerException:
       at com.veepee.pickuppoint.ui.PickUpPointActivity.parameter_delegate$lambda$2(PickUpPointActivity.java:596)
       at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
       at com.veepee.pickuppoint.ui.PickUpPointActivity.parameter_delegate$lambda$2(PickUpPointActivity.kt:114)
       at com.veepee.pickuppoint.ui.PickUpPointActivity.getParameter(PickUpPointActivity.kt:114)
       at com.veepee.pickuppoint.ui.PickUpPointActivity.onCreate(PickUpPointActivity.kt:176)
       at android.app.Activity.performCreate(Activity.java:8305)
       at android.app.Activity.performCreate(Activity.java:8284)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1417)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3626)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3782)
       at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101)
       at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2307)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loopOnce(Looper.java:201)
       at android.os.Looper.loop(Looper.java:288)
       at android.app.ActivityThread.main(ActivityThread.java:7872)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
this is my code
Copy code
private val parameter by lazy { requireLinkParameter<PickUpPointActivityParameter>() }

... 
    override fun onCreate(savedInstanceState: Bundle?) {
        if (parameter.shouldDoSomething) {
            // do something
        }
requireLinkParameter
just reads an
Intent
Parcelable, but the error is not saying that the Parcelable is null or anything. Any idea of what can be happening ?
g
You are sure this is 596 line no of pickUpPointactivity. You need to tell more context
j
That is generated code from kotlin compiler.. the class in my codebase is in kotlin. I tried to to use "Show kotlin bytecode", but I get the mensage "Cannot compile PickUpPointActivity.kt to bytecode."
My project is compiling and running, just the tool in the IDE is failing.
g
I can help but with less info I can't do. I need to see code , you need to share screen on any platform like google meet or any other
j
this is a private project, so I can't post the whole Activity here... I tried in multiple versions of AS to decompile the source code, but it fails... the shared code contains the called places in the stacktrace though
hey, I am back with this issue, it seems it got worse and it is happening in other Activities, so I was able to find this on crashlytics
Copy code
Caused by java.lang.NullPointerException:
       at com.veepee.vpcore.route.BundleExtensionsKt.getLinkParameter(BundleExtensions.kt:41)
       at com.venteprivee.features.home.ui.HomesActivity.onCreate(HomesActivity.kt:123)
       at android.app.Activity.performCreate(Activity.java:8071)
This is odd, my code is doing
Copy code
intent.requireLinkParameter<HomesActivityParameter>()
that does this
Copy code
inline fun <reified T : ParcelableParameter> Intent.requireLinkParameter(): T {
    return getLinkParameter()!!
}

inline fun <reified T : ParcelableParameter> Intent.getLinkParameter(): T? {
    return IntentCompat.getParcelableExtra(this, LINK_PARAMETER, T::class.java)
}
from the decompiled code I found this
Copy code
Intent $this$requireLinkParameter$iv = this.getIntent();
         Intrinsics.checkNotNullExpressionValue($this$requireLinkParameter$iv, "getIntent(...)");
         $this$requireLinkParameter$iv = $this$requireLinkParameter$iv;
         int $i$f$requireLinkParameter = false;
         Intent $this$getLinkParameter$iv$iv = $this$requireLinkParameter$iv;
         int $i$f$getLinkParameter = false;
         Intrinsics.checkNotNull((ParcelableParameter)IntentCompat.getParcelableExtra($this$getLinkParameter$iv$iv, BundleExtensionsKt.getLINK_PARAMETER(), HomesActivityParameter.class));
From my code I am 100% sure that the intent contains a ParcelableParameter.