Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'java.lang.String com.dropbox.core.DbxRequestConfig.getUserLocale()' on a null object reference #347

Open
pramodkr123 opened this issue Oct 7, 2021 · 16 comments
Labels
Milestone

Comments

@pramodkr123
Copy link

pramodkr123 commented Oct 7, 2021

Login with dropbox account I got crash.
implementation 'com.dropbox.core:dropbox-core-sdk:4.0.1'
Api level 30

My Code :

public class DbxRequestConfigFactory {
private static DbxRequestConfig sDbxRequestConfig;
public static DbxRequestConfig getRequestConfig() {
if (sDbxRequestConfig == null) {
sDbxRequestConfig = DbxRequestConfig.newBuilder("myapp-dropbox-v2")
.withHttpRequestor(new OkHttp3Requestor(OkHttp3Requestor.defaultOkHttpClient()))
.build();
}
return sDbxRequestConfig;
}
}

Auth.startOAuth2PKCE(this, getString(R.string.app_key),DbxRequestConfigFactory.getRequestConfig());

Logs below

Fatal Exception: java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$4.done(AsyncTask.java:399)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
at java.util.concurrent.FutureTask.run(FutureTask.java:271)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:289)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:919)

Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.dropbox.core.DbxRequestConfig.getUserLocale()' on a null object reference
at com.dropbox.core.DbxPKCEManager.makeTokenRequest(DbxPKCEManager.java:107)
at com.dropbox.core.android.AuthActivity$TokenRequestAsyncTask.doInBackground(AuthActivity.java:793)
at com.dropbox.core.android.AuthActivity$TokenRequestAsyncTask.doInBackground(AuthActivity.java:782)
at android.os.AsyncTask$3.call(AsyncTask.java:378)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:289)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:919)

@greg-db
Copy link
Contributor

greg-db commented Oct 7, 2021

Thanks for the report. I just tried running this code with the same Dropbox SDK version and Android API level you mentioned, but the exception doesn't occur for me. Can you double check the version of the SDK you have installed, and that this is the exact code you're running when this occurs? Also, can you check the value returned by DbxRequestConfigFactory.getRequestConfig() at that point in the debugger?

@CMTRehan
Copy link

CMTRehan commented Nov 30, 2021

I am facing the same issue. Have you found a solution yet??

Dropbox-SDK 4.0.0
Android 8.1, 10, 11

I have recieved following crash report in crashlytics

Fatal Exception: java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$4.done(AsyncTask.java:399)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
at java.util.concurrent.FutureTask.run(FutureTask.java:271)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:289)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:919)

Caused by java.lang.NullPointerException: Attempt to read from field 'java.lang.String j4.l.b' on a null object reference
at com.dropbox.core.DbxRequestConfig.getUserLocale(DbxRequestConfig.java:110)
at com.dropbox.core.DbxPKCEManager.makeTokenRequest(DbxPKCEManager.java:107)
at com.dropbox.core.android.AuthActivity$TokenRequestAsyncTask.doInBackground(AuthActivity.java:793)
at com.dropbox.core.android.AuthActivity$TokenRequestAsyncTask.doInBackground(AuthActivity.java:782)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)

is this issue fixed in v5.0.0??

@greg-db
Copy link
Contributor

greg-db commented Nov 30, 2021

@CMTRehan We weren't able to reproduce the issue originally reported here, and we haven't heard back from the original commenter, so I don't have any information to add to this.

Your error message looks slightly different than the original one, but as a best practice I do recommend upgrading to the latest version of the SDK anyway, currently v5.0.0. If you're still seeing the issue with that, please share the necessary steps and code to reproduce the issue so we can look into it.

@tdtran
Copy link

tdtran commented Jan 12, 2022

An Android app initiates the OAuth sequence by calling one of the methods startOAuth... in the com.dropbox.core.android.Auth class. What happens next:

  1. Auth.startOAuth...() stores auth params in static fields of AuthActivity class, using AuthActivity.setAuthParams(). That includes AuthActivity.sRequestConfig

  2. An instance of AuthActivity class is created by Android, its onCreate() method is called, instance field mRequestConfig is set to sRequestConfig

  3. This instance of AuthAcitivty calls startActivity() and passes control to Dropbox app or web browser. It also resets the auth params by calling setAuthParams(null, null, null). This sets the static field sRequestConfig = null

  4. Dropbox app (or browser) passes the OAuth token back to our app. The method AuthActivity.onNewIntent is supposed to capture and parse this OAuth token.

The problem is the AuthActivity instance at step 3 may not be the same instance created at step 1. Android is free to kill and re-create activities as it wishes. It's quite easy to reproduce such a situation. Between step 2 and step 3 when we are in the browser or Dropbox app, rotate the device to change its screen orientation. Then tap on "Allow" button.

Android now wants to go back to AuthActivity, but it cannot reuse the existing AuthActivity instance because the screen orientation changed. It discards the old instance and creates a new one, call its onCreate() method which sets mRequestConfig to sRequestConfig which is null........ CRASH

The sample Android app in Dropbox SDK has this in its AndroidManifest.xml:

<activity
            android:name="com.dropbox.core.android.AuthActivity"
            android:configChanges="orientation|keyboard"
...

It tries to prevent re-creation of the activity with android:configChanges="orientation|keyboard". This is bad practice and does not always work. I can reliably cause the crash even with this property set by rotating my Android 12 phone.

@greg-db
Copy link
Contributor

greg-db commented Jan 13, 2022

@tdtran Thanks for the detailed message! That's very helpful. We'll look into it.

@bubbleguuum
Copy link

bubbleguuum commented May 30, 2022

Still happening on 5.2.0, though probably fairly rare. Seen reported on a Samsung Android 12 device:

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.dropbox.core.DbxRequestConfig.getUserLocale()' on a null object reference
at com.dropbox.core.DbxPKCEManager.makeTokenRequest(DbxPKCEManager.java:107)
at com.dropbox.core.android.AuthActivity$TokenRequestAsyncTask.doInBackground(AuthActivity.java:793)
at com.dropbox.core.android.AuthActivity$TokenRequestAsyncTask.doInBackground(AuthActivity.java:782)
at android.os.AsyncTask$3.call(AsyncTask.java:394)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:305)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)

@greg-db
Copy link
Contributor

greg-db commented May 30, 2022

@bubbleguuum Thanks for the note! This is still open with the team.

@kruil
Copy link

kruil commented Sep 18, 2022

I can confirm it still happens on 5.3.0 =( . Please fix it.

Fatal Exception: java.lang.RuntimeException: An error occurred while executing doInBackground()
       at android.os.AsyncTask$4.done(AsyncTask.java:415)
       at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:381)
       at java.util.concurrent.FutureTask.setException(FutureTask.java:250)
       at java.util.concurrent.FutureTask.run(FutureTask.java:269)
       at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:305)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
       at java.lang.Thread.run(Thread.java:1012)

Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.dropbox.core.DbxRequestConfig.getUserLocale()' on a null object reference
       at com.dropbox.core.DbxPKCEManager.makeTokenRequest(DbxPKCEManager.java:107)
       at com.dropbox.core.android.AuthActivity$TokenRequestAsyncTask.doInBackground(AuthActivity.java:793)
       at com.dropbox.core.android.AuthActivity$TokenRequestAsyncTask.doInBackground(AuthActivity.java:782)
       at android.os.AsyncTask$3.call(AsyncTask.java:394)
       at java.util.concurrent.FutureTask.run(FutureTask.java:264)
       at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:305)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
       at java.lang.Thread.run(Thread.java:1012)

@greg-db
Copy link
Contributor

greg-db commented Sep 19, 2022

@kruil Thanks for the information. This is still open with the team, and I'll follow up here once I have an update on it.

@handstandsam
Copy link
Contributor

Fixed in #443, will be releasing 5.4.0 by early next week.

@handstandsam handstandsam added this to the 5.4.0 milestone Sep 23, 2022
@greg-db
Copy link
Contributor

greg-db commented Oct 4, 2022

Update: v5.4.2 is out with the fix for this. Please use that and let us know if you're still seeing any issues. Thanks!

@alexplanetart
Copy link

alexplanetart commented Oct 19, 2022

Still crash on v5.4.2!!! Nothing changed.

@devPalacio
Copy link
Contributor

@alexplanetart could you provide us with a stacktrace of the crash?

@handstandsam
Copy link
Contributor

@devPalacio @alexplanetart - I see the stack traces from before. It walked through some of the flows and it looks like locale can be nullable. I can't address this immediately because I'm out of town, but can get this in a patch version soon.

Sorry, I thought this nullability was handled in the Kotlin conversion, but it wasn't because it's a nested property.

Will get to this and get a fix early next week. Cheers.

@handstandsam handstandsam reopened this Oct 19, 2022
@alexplanetart
Copy link

@devPalacio
image

@alexplanetart
Copy link

@handstandsam @devPalacio
The latest version 5.4.2 seems to have ANR problem. This problem did not occur in the previous version, although it only happened once now. Please check the reason for this problem.
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants