diff --git a/maven-model/src/main/java/org/apache/maven/model/BaseObject.java b/maven-model/src/main/java/org/apache/maven/model/BaseObject.java index 22c7a6efc4e1..8691fff48040 100644 --- a/maven-model/src/main/java/org/apache/maven/model/BaseObject.java +++ b/maven-model/src/main/java/org/apache/maven/model/BaseObject.java @@ -35,7 +35,7 @@ public BaseObject(Object delegate, BaseObject parent) { } public BaseObject(Object delegate, ChildrenTracking parent) { - this.delegate = delegate; + this.delegate = requireNonNull(delegate, "delegate cannot be null"); this.childrenTracking = parent; } diff --git a/maven-repository-metadata/src/main/java/org/apache/maven/artifact/repository/metadata/BaseObject.java b/maven-repository-metadata/src/main/java/org/apache/maven/artifact/repository/metadata/BaseObject.java index c206298e2bc4..8c6f01f238f5 100644 --- a/maven-repository-metadata/src/main/java/org/apache/maven/artifact/repository/metadata/BaseObject.java +++ b/maven-repository-metadata/src/main/java/org/apache/maven/artifact/repository/metadata/BaseObject.java @@ -20,6 +20,8 @@ import java.io.Serializable; +import static java.util.Objects.requireNonNull; + public abstract class BaseObject implements Serializable, Cloneable { protected transient ChildrenTracking childrenTracking; @@ -28,12 +30,12 @@ public abstract class BaseObject implements Serializable, Cloneable { public BaseObject() {} public BaseObject(Object delegate, BaseObject parent) { - this.delegate = delegate; + this.delegate = requireNonNull(delegate, "delegate cannot be null"); this.childrenTracking = parent != null ? parent::replace : null; } public BaseObject(Object delegate, ChildrenTracking parent) { - this.delegate = delegate; + this.delegate = requireNonNull(delegate, "delegate cannot be null"); this.childrenTracking = parent; } diff --git a/maven-settings/src/main/java/org/apache/maven/settings/BaseObject.java b/maven-settings/src/main/java/org/apache/maven/settings/BaseObject.java index 7b66110a8bef..b656ff7b42db 100644 --- a/maven-settings/src/main/java/org/apache/maven/settings/BaseObject.java +++ b/maven-settings/src/main/java/org/apache/maven/settings/BaseObject.java @@ -20,6 +20,8 @@ import java.io.Serializable; +import static java.util.Objects.requireNonNull; + public abstract class BaseObject implements Serializable, Cloneable { protected transient ChildrenTracking childrenTracking; @@ -28,12 +30,12 @@ public abstract class BaseObject implements Serializable, Cloneable { public BaseObject() {} public BaseObject(Object delegate, BaseObject parent) { - this.delegate = delegate; + this.delegate = requireNonNull(delegate, "delegate cannot be null"); this.childrenTracking = parent != null ? parent::replace : null; } public BaseObject(Object delegate, ChildrenTracking parent) { - this.delegate = delegate; + this.delegate = requireNonNull(delegate, "delegate cannot be null"); this.childrenTracking = parent; } diff --git a/maven-toolchain-model/src/main/java/org/apache/maven/toolchain/model/BaseObject.java b/maven-toolchain-model/src/main/java/org/apache/maven/toolchain/model/BaseObject.java index 28bea64b8ea7..3a844a77c928 100644 --- a/maven-toolchain-model/src/main/java/org/apache/maven/toolchain/model/BaseObject.java +++ b/maven-toolchain-model/src/main/java/org/apache/maven/toolchain/model/BaseObject.java @@ -20,6 +20,8 @@ import java.io.Serializable; +import static java.util.Objects.requireNonNull; + public abstract class BaseObject implements Serializable, Cloneable { protected transient ChildrenTracking childrenTracking; @@ -28,12 +30,12 @@ public abstract class BaseObject implements Serializable, Cloneable { public BaseObject() {} public BaseObject(Object delegate, BaseObject parent) { - this.delegate = delegate; + this.delegate = requireNonNull(delegate, "delegate cannot be null"); this.childrenTracking = parent != null ? parent::replace : null; } public BaseObject(Object delegate, ChildrenTracking parent) { - this.delegate = delegate; + this.delegate = requireNonNull(delegate, "delegate cannot be null"); this.childrenTracking = parent; }