AndroidHttpClient Nullpointerexception calling android.net.http.AndroidHttpClient.isMmsRequest

1.3k views Asked by At

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.

1

There are 1 answers

5
mldeveloper On

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.