[go: nahoru, domu]

Skip to content

Commit

Permalink
Catch NPE in Bitmap.CreateBitmap and make sure the returned bitmap is…
Browse files Browse the repository at this point in the history
… not null
  • Loading branch information
Danilo Ercoli authored and Danilo Ercoli committed Sep 10, 2014
1 parent 96fd180 commit 343771a
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -444,16 +444,17 @@ public static byte[] createThumbnailFromUri(Context context,
optActual.inSampleSize = scale;

// Get the roughly resized bitmap
Bitmap bmpResized;
final Bitmap bmpResized;
try {
bmpResized = BitmapFactory.decodeFile(filePath, optActual);
} catch (OutOfMemoryError e) {
AppLog.e(AppLog.T.UTILS, "OutOfMemoryError Error in setting image: " + e);
return null;
}

if (bmpResized == null)
if (bmpResized == null) {
return null;
}

ByteArrayOutputStream stream = new ByteArrayOutputStream();

Expand Down Expand Up @@ -490,7 +491,18 @@ public static byte[] createThumbnailFromUri(Context context,
} catch (OutOfMemoryError e) {
AppLog.e(AppLog.T.UTILS, "OutOfMemoryError Error in setting image: " + e);
return null;
} catch (NullPointerException e) {
// See: https://github.com/wordpress-mobile/WordPress-Android/issues/1844
AppLog.e(AppLog.T.UTILS, "Bitmap.createBitmap has thrown a NPE internally. This should never happen: " + e);
return null;
}

if (bmpRotated == null) {
// Fix an issue where bmpRotated is null even if the documentation doesn't say Bitmap.createBitmap can return null.
// See: https://github.com/wordpress-mobile/WordPress-Android/issues/1848
return null;
}

bmpRotated.compress(fmt, 100, stream);
bmpResized.recycle();
bmpRotated.recycle();
Expand Down

0 comments on commit 343771a

Please sign in to comment.