Fix NullPointerException in NinePatch constructor

NinePatch.mPaint may be null and most methods in this class handle
that case properly. However, the constructor which derives a new
NinePatch from an existing instance assumes that mPaint is non-null.
This results in an unexpected NullPointerException, for example when
attempting to call NinePatchDrawable.mutate() on an instance that was
created from a resource.

Small unrelated fix in same file: Remove unused private mRect member.
This commit is contained in:
Phil Dubach
2009-06-29 20:34:13 -07:00
parent 72d19aa51e
commit 54285f2cbf

View File

@@ -57,7 +57,9 @@ public class NinePatch {
mBitmap = patch.mBitmap;
mChunk = patch.mChunk;
mSrcName = patch.mSrcName;
mPaint = new Paint(patch.mPaint);
if (patch.mPaint != null) {
mPaint = new Paint(patch.mPaint);
}
validateNinePatchChunk(mBitmap.ni(), mChunk);
}
@@ -120,7 +122,6 @@ public class NinePatch {
public native static boolean isNinePatchChunk(byte[] chunk);
private final Rect mRect = new Rect();
private final Bitmap mBitmap;
private final byte[] mChunk;
private Paint mPaint;