8

A customer has reported a strange error. When doing a normal AndroidHttpClient.execute() in an AsyncTask, the app crashes and he gets the following stack trace

java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:299)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
at java.util.concurrent.FutureTask.run(FutureTask.java:239)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:841)
Caused by: java.lang.NullPointerException
at android.net.http.AndroidHttpClient.isMmsRequest(AndroidHttpClient.java:257)
at android.net.http.AndroidHttpClient.checkMmsSendPermission(AndroidHttpClient.java:290)
at android.net.http.AndroidHttpClient.execute(AndroidHttpClient.java:296)
at com.xxx.xxx.MyClass$MyHandler.doWork(MyClass.java:325)
at  com.xxx.xxx.NetworkRequestHandler$AsyncTaskForRequestHandler.doInBackground(NetworkRequestHandler.java:532)
at com.xxx.xxx.utils.network.NetworkRequestHandler$AsyncTaskForRequestHandler.doInBackground(NetworkRequestHandler.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
... 3 more

Why is it calling checkMMSSendPermission and isSmsRequest? We are not using MMS and SMS at all, and the application do not have those permissions, which I guess is why it crashes. This works for all other 99.9% of our users.

Code looks like this

AndroidHttpClient client = AndroidHttpClient.newInstance(null);
        InputStream inputStream = null;
        try
        {
            HttpPost request = new HttpPost(urlString);
            prepareURLRequest(request);
            HttpResponse response = client.execute(request);
            mResultStatus = response.getStatusLine().getStatusCode();
            inputStream = response.getEntity().getContent();
...

Any help would be welcome

Update

This seems to be only affecting Sony Xperia Z, Z1 and ZR phones. Apparently the problems started to occur after receiving the update to Android 4.3. No one with those phones can use our app but for all else, it works.

KlasE
  • 142
  • 11
  • 2
    use `HttpClient client = new DefaultHttpClient();` – Raghunandan Dec 09 '13 at 14:58
  • Thank your for your comment. Does that solve the problem with MMS? Have you seen this issue before? – KlasE Dec 09 '13 at 21:23
  • I've run into the same problem on one Sony XL39h. And it works after change to `DefaultHttpClient`. Have you found an solution for this problem without changing the `HttpClient`? – Zhao Xiang Jan 13 '14 at 04:39
  • Yes, one workaround is to change to DefaultHttpClient. However I've had issues with other versions of android and DefaultHttpClient together with SSL and certain POST calls. What I eventually did was to only use HttpURLConnection for 4.x, and for android < 4.x, I kept the code using AndroidHttpClient. Not nice but now it works for all android versions. I would really want to know why on Sony phones it asks for MMS permissions when using AndroidHttpClient. – KlasE Jan 15 '14 at 09:05
  • it affects Z Ultra too. – Raiv Jan 30 '14 at 13:49
  • Bug seems to be in custom ROM which manufacturers have included. Check this. https://github.com/CyanogenMod/android_frameworks_base/commit/d50f8ada8c3693295c348359e8201d75c9d07f2c – NinjaCoder Mar 02 '15 at 17:29

1 Answers1

2

Not sure why it's making calls to MMS and SMS methods but try doing this:

DefaultHttpClient client = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
try {
    HttpResponse execute = client.execute(httpPost);
    InputStream content = execute.getEntity().getContent();

This should work without any crashes.

mldeveloper
  • 2,253
  • 1
  • 13
  • 14
  • Thank you for responding. I will verify that. However, I have ran into problems with DefaultHttpClient previously with older Android versions. Unfortunately, I don't remember exactly what those problems were. What I do know is that normal HttpUrlConnection is working for all Android 4.x versions. Unfortunately, there are issues with 2.x devices when it comes to doing POST together with SSL and an empty body. AndroidHttpClient was the only one I got working using the same code for all android versions. And now that option is gone as well, and it seems to only be a problem with Xperia, how come? – KlasE Jan 08 '14 at 22:41
  • Maybe I should rephrase the question above. What I really want to know is why It checks for MMS permission when using AndroidHttpClient and why it fails with a NullPointerException? – KlasE Jan 08 '14 at 22:50
  • 1
    I suppose this is a firmware bug – Raiv Jan 30 '14 at 13:54
  • 1
    I'm also facing this issue in one of our Apps. @KlasE Have you faced any problems after switching to DefaultHttpClient for this? – rineez Feb 17 '14 at 05:32
  • 1
    I never used DefaultHttpClient. I solved it by using HttpURLConnection for Android versions 4+, and kept AndroidHttpClient for older versions. Not pretty to have two implementations but it was the safe way to proceed. I'm still waiting for Sony to respond with a solution, not just offer a workaround. – KlasE Feb 17 '14 at 11:19