0

I'm having a strange NPE with the following stacktrace:

Fatal Exception: java.lang.NullPointerException: Attempt to read from field 'int com.foo.gvpclient.x.c' on a null object reference
       at com.foo.gvpclient.GVPConfiguration.getDeviceTypeAsString(GVPConfiguration.java:507)
       at com.foo.gvpclient.request.uniapi.authentication.LoginAnonymousRequest.<init>(LoginAnonymousRequest.java:39)
       at com.foo.bar.analytics.managers.AnalyticsManager.sendEventsBatchAsAnonymous(AnalyticsManager.java:489)
       at com.foo.bar.analytics.managers.AnalyticsManager.addEvent(AnalyticsManager.java:324)
       at com.foo.bar.analytics.managers.AnalyticsManager.onBrowseEvent(AnalyticsManager.java:266)
       at com.foo.bar.analytics.managers.AnalyticsManager.onBrowseEvent(AnalyticsManager.java:231)
       at com.foo.bar.analytics.managers.AnalyticsManager.onBrowseEvent(AnalyticsManager.java:711)
       at com.foo.bar.login.activities.LoginActivity.register(LoginActivity.java:469)
       at com.foo.bar.login.activities.LoginActivity.access$register(LoginActivity.java:51)
       at com.foo.bar.login.activities.LoginActivity$onCreate$$inlined$apply$lambda$1.onClick(LoginActivity.java:123)
       at android.view.View.performClick(View.java:7339)
       at android.widget.TextView.performClick(TextView.java:14221)
       at android.view.View.performClickInternal(View.java:7305)
       at android.view.View.access$3200(View.java:846)
       at android.view.View$PerformClick.run(View.java:27787)
       at android.os.Handler.handleCallback(Handler.java:873)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:214)
       at android.app.ActivityThread.main(ActivityThread.java:7076)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)

This is getDeviceTypeAsString() method:

public String getDeviceTypeAsString() {
    return String.valueOf(this.mDeviceType);
}

where mDeviceType is declared as

private int mDeviceType;

Please correct me if I'm wrong but there's nothing here that can be null.

For the sake of completion, the method is called from here:

public LoginAnonymousRequest(GVPConfiguration gvpConfig) {
    super(gvpConfig);
    // More unrelated stuff
    this.mQueryStringParams.put("deviceType", this.mGvpConfig.getDeviceTypeAsString());
}

Again, correct me if I'm wrong but if gvpConfig is null in the constructor above, then the NPE would have been thrown at this.mGvpConfig.getDeviceTypeAsString() and not inside the method itself.

So what's causing this NPE? Could it be something related to code obfuscation?

m0skit0
  • 25,268
  • 11
  • 79
  • 127

1 Answers1

2

It's not obfuscation but optimization done by the same tooling such as proguard or r8.

Basically, the simple accessor is optimized as inline in the caller and it's in fact the GVPConfiguration object at call site that is null.

laalto
  • 150,114
  • 66
  • 286
  • 303