From f135b271bfaa5a23f3af5a15ce59fd4ffb44a6be Mon Sep 17 00:00:00 2001 From: Christopher Tate Date: Fri, 27 May 2016 17:10:30 -0700 Subject: [PATCH] Don't call .toString() on potentially null CharSequence We're building an exception message string, but by explicitly invoking .toString() we're accidentally triggering an NPE rather than the typed exception we want to throw. Build the string in a way that will be safe and sensical even if the CharSequence is null. Bug 29009255 Change-Id: I1813260f0b36fd44506b8327f997dd20c2d6c8bf --- core/java/android/content/res/ResourcesImpl.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/java/android/content/res/ResourcesImpl.java b/core/java/android/content/res/ResourcesImpl.java index 32a27951677a7..000751e886398 100644 --- a/core/java/android/content/res/ResourcesImpl.java +++ b/core/java/android/content/res/ResourcesImpl.java @@ -292,8 +292,10 @@ public class ResourcesImpl { return mAssets.openNonAsset(value.assetCookie, value.string.toString(), AssetManager.ACCESS_STREAMING); } catch (Exception e) { - NotFoundException rnf = new NotFoundException("File " + value.string.toString() + - " from drawable resource ID #0x" + Integer.toHexString(id)); + // Note: value.string might be null + NotFoundException rnf = new NotFoundException("File " + + (value.string == null ? "(null)" : value.string.toString()) + + " from drawable resource ID #0x" + Integer.toHexString(id)); rnf.initCause(e); throw rnf; }