Skip to content

Commit 92f8f09

Browse files
committed
InsertImageTask: handle potential nullpointer if image is corrupt
1 parent 713f80f commit 92f8f09

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

app/src/main/java/org/gateshipone/odyssey/artwork/network/InsertImageTask.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ protected ArtworkRequestModel doInBackground(ImageResponse... params) {
8181
float factor = Math.min((float) MAXIMUM_IMAGE_RESOLUTION / (float) options.outHeight, (float) MAXIMUM_IMAGE_RESOLUTION / (float) options.outWidth);
8282
options.inJustDecodeBounds = false;
8383
Bitmap bm = BitmapFactory.decodeByteArray(response.image, 0, response.image.length, options);
84+
if (bm == null) {
85+
// In rare cases the received byte array can be corrupted and so the image decoding will fail and result in a null bitmap.
86+
// In this case we will behave the same way as the response would contain a null byte array.
87+
insertImage(response.model, null, response.localArtworkPath);
88+
return response.model;
89+
}
8490
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
8591
Bitmap.createScaledBitmap(bm, (int) (options.outWidth * factor), (int) (options.outHeight * factor), true)
8692
.compress(Bitmap.CompressFormat.JPEG, IMAGE_COMPRESSION_SETTING, byteStream);

0 commit comments

Comments
 (0)