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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user