Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NPE messages for HasComponents #4442

Merged
merged 1 commit into from
Jul 27, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.vaadin.flow.component;

import java.util.Objects;

import com.vaadin.flow.dom.Element;

/**
Expand All @@ -39,9 +41,10 @@ public interface HasComponents extends HasElement, HasEnabled {
* the components to add
*/
default void add(Component... components) {
assert components != null;
Objects.requireNonNull(components, "Components should not be null");
for (Component component : components) {
assert component != null;
Objects.requireNonNull(component,
"Component to add cannot be null");
getElement().appendChild(component.getElement());
}
}
Expand All @@ -55,8 +58,10 @@ default void add(Component... components) {
* if any of the components is not a child of this component
*/
default void remove(Component... components) {
Objects.requireNonNull(components, "Components should not be null");
for (Component component : components) {
assert component != null;
Objects.requireNonNull(component,
"Component to remove cannot be null");
if (getElement().equals(component.getElement().getParent())) {
getElement().removeChild(component.getElement());
} else {
Expand Down