collect icon indicating copy to clipboard operation
collect copied to clipboard

Trying to get blank form from My Drive crashes the app

Open pratikmjoshi opened this issue 9 years ago • 5 comments

Android v6.0.1, device used: OnePlus One

Steps to reproduce problem:

  1. In General Settings, selected my Google account. 2.Went back to Main Menu and selected Get Blank Form 3.Selected My Drive Button to browse forms. As soon as I do the above, the app crashes with the following log.

03-12 23:01:22.541 32116-11395/org.odk.collect.android E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #5 Process: org.odk.collect.android, PID: 32116 Theme: themes:{default=overlay:system, iconPack:system, fontPkg:system, com.android.systemui=overlay:system, com.android.systemui.navbar=overlay:system} java.lang.RuntimeException: An error occurred while executing doInBackground() at android.os.AsyncTask$3.done(AsyncTask.java:309) at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354) at java.util.concurrent.FutureTask.setException(FutureTask.java:223) at java.util.concurrent.FutureTask.run(FutureTask.java:242) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) at java.lang.Thread.run(Thread.java:818) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object com.google.api.services.drive.Drive$Files$List.execute()' on a null object reference at org.odk.collect.android.activities.GoogleDriveActivity$RetrieveDriveFileContentsAsyncTask.doInBackground(GoogleDriveActivity.java:617) at org.odk.collect.android.activities.GoogleDriveActivity$RetrieveDriveFileContentsAsyncTask.doInBackground(GoogleDriveActivity.java:529) at android.os.AsyncTask$2.call(AsyncTask.java:295) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) at java.lang.Thread.run(Thread.java:818)

It should be allowing me to browse my drive and select forms. Can I work on this issue?

pratikmjoshi avatar Mar 12 '17 17:03 pratikmjoshi

When filing an issue, please make sure to follow the template and include information about the versions you are using and the exact steps that must be followed to get the error.

Before you write code to address it, what is your hypothesis on what is causing the problem?

lognaturel avatar Mar 13 '17 00:03 lognaturel

@lognaturel Sorry about that. Updated the issue I did look at the code and tried to fix the problem. It seems that the files list(request) is not being retrieved because the request is null. I would like to suggest that generally try-catch methods should not be put inside loops(such as do-while, and while). It does not catch exceptions at all. It should be that loops should be placed inside the try-catch. When I did so, the app stopped crashing.

However, since I do not have any forms in my Google Drive, it should show that I don't. I am not entirely sure why the nullexception is happening in the first place(It shouldn't). But I'll look into it.

I can send a PR now if you wish, since the app stops crashing at that point. I can later add another issue to solve the reason behind the nullexception.

pratikmjoshi avatar Mar 13 '17 07:03 pratikmjoshi

@pratikmjoshi Did you follow those steps ?

grzesiek2010 avatar Mar 13 '17 09:03 grzesiek2010

@grzesiek2010 My bad. I had done it originally, but I think I made a mistake somewhere. Just followed the steps properly again now and it works. I'll close this issue.

Just a side note, can I open an issue on try-catches being inside loops? I've seen this in the code a few times, and I can put the loop inside the try-catches, because try-catches inside loops aren't good practice generally.

pratikmjoshi avatar Mar 13 '17 09:03 pratikmjoshi

@pratikmjoshi I didn't investigate this but if you are sure it should be improved you can file the issue for code refactoring.

grzesiek2010 avatar Mar 13 '17 10:03 grzesiek2010