Skip to content

Commit c7476fc

Browse files
committed
Merge branch 'hotfix/3.1.2' into release/3.2
Conflicts: WordPress/src/main/java/org/wordpress/android/GCMIntentService.java
2 parents e3795fe + 0ebd130 commit c7476fc

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

WordPressUtils/src/main/java/org/wordpress/android/util/ImageUtils.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)