am 02091f07: am 19a9e6c2: Merge "Throw a more descriptive exception when adding null to a ViewGroup" into lmp-mr1-dev
* commit '02091f071ad2b4754c9f4c7a66738d0d661c0c0e': Throw a more descriptive exception when adding null to a ViewGroup
This commit is contained in:
@@ -3671,6 +3671,9 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
|
|||||||
* @see #generateDefaultLayoutParams()
|
* @see #generateDefaultLayoutParams()
|
||||||
*/
|
*/
|
||||||
public void addView(View child, int index) {
|
public void addView(View child, int index) {
|
||||||
|
if (child == null) {
|
||||||
|
throw new IllegalArgumentException("Cannot add a null child view to a ViewGroup");
|
||||||
|
}
|
||||||
LayoutParams params = child.getLayoutParams();
|
LayoutParams params = child.getLayoutParams();
|
||||||
if (params == null) {
|
if (params == null) {
|
||||||
params = generateDefaultLayoutParams();
|
params = generateDefaultLayoutParams();
|
||||||
@@ -3728,6 +3731,10 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
|
|||||||
System.out.println(this + " addView");
|
System.out.println(this + " addView");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (child == null) {
|
||||||
|
throw new IllegalArgumentException("Cannot add a null child view to a ViewGroup");
|
||||||
|
}
|
||||||
|
|
||||||
// addViewInner() will call child.requestLayout() when setting the new LayoutParams
|
// addViewInner() will call child.requestLayout() when setting the new LayoutParams
|
||||||
// therefore, we call requestLayout() on ourselves before, so that the child's request
|
// therefore, we call requestLayout() on ourselves before, so that the child's request
|
||||||
// will be blocked at our level
|
// will be blocked at our level
|
||||||
@@ -3855,6 +3862,9 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
|
|||||||
*/
|
*/
|
||||||
protected boolean addViewInLayout(View child, int index, LayoutParams params,
|
protected boolean addViewInLayout(View child, int index, LayoutParams params,
|
||||||
boolean preventRequestLayout) {
|
boolean preventRequestLayout) {
|
||||||
|
if (child == null) {
|
||||||
|
throw new IllegalArgumentException("Cannot add a null child view to a ViewGroup");
|
||||||
|
}
|
||||||
child.mParent = null;
|
child.mParent = null;
|
||||||
addViewInner(child, index, params, preventRequestLayout);
|
addViewInner(child, index, params, preventRequestLayout);
|
||||||
child.mPrivateFlags = (child.mPrivateFlags & ~PFLAG_DIRTY_MASK) | PFLAG_DRAWN;
|
child.mPrivateFlags = (child.mPrivateFlags & ~PFLAG_DIRTY_MASK) | PFLAG_DRAWN;
|
||||||
|
|||||||
Reference in New Issue
Block a user