@@ -444,16 +444,17 @@ public static byte[] createThumbnailFromUri(Context context,
444444 optActual .inSampleSize = scale ;
445445
446446 // Get the roughly resized bitmap
447- Bitmap bmpResized ;
447+ final Bitmap bmpResized ;
448448 try {
449449 bmpResized = BitmapFactory .decodeFile (filePath , optActual );
450450 } catch (OutOfMemoryError e ) {
451451 AppLog .e (AppLog .T .UTILS , "OutOfMemoryError Error in setting image: " + e );
452452 return null ;
453453 }
454454
455- if (bmpResized == null )
455+ if (bmpResized == null ) {
456456 return null ;
457+ }
457458
458459 ByteArrayOutputStream stream = new ByteArrayOutputStream ();
459460
@@ -490,7 +491,18 @@ public static byte[] createThumbnailFromUri(Context context,
490491 } catch (OutOfMemoryError e ) {
491492 AppLog .e (AppLog .T .UTILS , "OutOfMemoryError Error in setting image: " + e );
492493 return null ;
494+ } catch (NullPointerException e ) {
495+ // See: https://github.com/wordpress-mobile/WordPress-Android/issues/1844
496+ AppLog .e (AppLog .T .UTILS , "Bitmap.createBitmap has thrown a NPE internally. This should never happen: " + e );
497+ return null ;
498+ }
499+
500+ if (bmpRotated == null ) {
501+ // Fix an issue where bmpRotated is null even if the documentation doesn't say Bitmap.createBitmap can return null.
502+ // See: https://github.com/wordpress-mobile/WordPress-Android/issues/1848
503+ return null ;
493504 }
505+
494506 bmpRotated .compress (fmt , 100 , stream );
495507 bmpResized .recycle ();
496508 bmpRotated .recycle ();
0 commit comments