AndroidHttpClient Nullpointerexception calling android.net.http.AndroidHttpClient.isMmsRequest
Asked Answered
R

1

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.

Raze answered 9/12, 2013 at 14:56 Comment(6)
use HttpClient client = new DefaultHttpClient();Stereometry
Thank your for your comment. Does that solve the problem with MMS? Have you seen this issue before?Raze
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?Blain
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.Raze
it affects Z Ultra too.Photomechanical
Bug seems to be in custom ROM which manufacturers have included. Check this. github.com/CyanogenMod/android_frameworks_base/commit/…Lek
K
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.

Kimura answered 8/1, 2014 at 19:35 Comment(5)
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?Raze
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?Raze
I suppose this is a firmware bugPhotomechanical
I'm also facing this issue in one of our Apps. @Raze Have you faced any problems after switching to DefaultHttpClient for this?Retreat
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.Raze

© 2022 - 2024 — McMap. All rights reserved.