Skip to content

Commit 183b9d8

Browse files
committed
Merge pull request android-async-http#352 from xAnubiSx/master
NPE fix in TextHttpResponseHandler and AsyncHttpResponseHandler
2 parents cc740d1 + 3f69332 commit 183b9d8

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

library/src/com/loopj/android/http/AsyncHttpResponseHandler.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,8 @@ public void onFailure(int statusCode, Header[] headers, Throwable error, String
291291
* @param error the underlying cause of the failure
292292
*/
293293
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
294-
String response;
295294
try {
296-
response = new String(responseBody, getCharset());
295+
String response = responseBody == null ? null : new String(responseBody, getCharset());
297296
onFailure(statusCode, headers, error, response);
298297
} catch (UnsupportedEncodingException e) {
299298
Log.e(LOG_TAG, e.toString());

library/src/com/loopj/android/http/TextHttpResponseHandler.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ public void onSuccess(int statusCode, Header[] headers, String responseBody) {
100100
@Override
101101
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
102102
try {
103-
onSuccess(statusCode, headers, new String(responseBody, getCharset()));
103+
String response = responseBody == null ? null : new String(responseBody, getCharset());
104+
onSuccess(statusCode, headers, response);
104105
} catch (UnsupportedEncodingException e) {
105106
Log.v(LOG_TAG, "String encoding failed, calling onFailure(int, Header[], String, Throwable)");
106107
onFailure(0, headers, (String) null, e);
@@ -110,7 +111,8 @@ public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
110111
@Override
111112
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
112113
try {
113-
onFailure(statusCode, headers, new String(responseBody, getCharset()), error);
114+
String response = responseBody == null ? null : new String(responseBody, getCharset());
115+
onFailure(statusCode, headers, response, error);
114116
} catch (UnsupportedEncodingException e) {
115117
Log.v(LOG_TAG, "String encoding failed, calling onFailure(int, Header[], String, Throwable)");
116118
onFailure(0, headers, (String) null, e);

0 commit comments

Comments
 (0)