diff --git a/patterns/design-patterns-2/pom.xml b/patterns/design-patterns-2/pom.xml
index 2a0213065b..5c3e70b046 100644
--- a/patterns/design-patterns-2/pom.xml
+++ b/patterns/design-patterns-2/pom.xml
@@ -15,11 +15,29 @@
+
+ org.jetbrains
+ annotations
+ ${intellij.annotations.version}
+
+
+ org.projectlombok
+ lombok
+ ${lombok.version}
+ provided
+
+
+ org.apache.commons
+ commons-lang3
+ ${commons-lang3.version}
+
UTF-8
1.8
1.8
+ 16.0.2
+ 3.5
diff --git a/patterns/design-patterns-2/src/main/java/com/baeldung/nulls/APIContracts.java b/patterns/design-patterns-2/src/main/java/com/baeldung/nulls/APIContracts.java
new file mode 100644
index 0000000000..7d6abf53b8
--- /dev/null
+++ b/patterns/design-patterns-2/src/main/java/com/baeldung/nulls/APIContracts.java
@@ -0,0 +1,30 @@
+package com.baeldung.nulls;
+
+public class APIContracts {
+
+ /**
+ * Prints the value of {@code param} if not null. Prints {@code null} otherwise.
+ *
+ * @param param
+ */
+ public void print(Object param) {
+ System.out.println("Printing " + param);
+ }
+
+ /**
+ * @return non null result
+ * @throws Exception - if result is null
+ */
+ public Object process() throws Exception {
+ Object result = doSomething();
+ if (result == null) {
+ throw new Exception("Processing fail. Got a null response");
+ } else {
+ return result;
+ }
+ }
+
+ private Object doSomething() {
+ return null;
+ }
+}
diff --git a/patterns/design-patterns-2/src/main/java/com/baeldung/nulls/Assertions.java b/patterns/design-patterns-2/src/main/java/com/baeldung/nulls/Assertions.java
new file mode 100644
index 0000000000..a0d692623f
--- /dev/null
+++ b/patterns/design-patterns-2/src/main/java/com/baeldung/nulls/Assertions.java
@@ -0,0 +1,13 @@
+package com.baeldung.nulls;
+
+public class Assertions {
+
+ public void accept(Object param){
+ assert param != null;
+
+ doSomething(param);
+ }
+
+ private void doSomething(Object param) {
+ }
+}
diff --git a/patterns/design-patterns-2/src/main/java/com/baeldung/nulls/EmptyCollections.java b/patterns/design-patterns-2/src/main/java/com/baeldung/nulls/EmptyCollections.java
new file mode 100644
index 0000000000..5958cf8dc6
--- /dev/null
+++ b/patterns/design-patterns-2/src/main/java/com/baeldung/nulls/EmptyCollections.java
@@ -0,0 +1,25 @@
+package com.baeldung.nulls;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class EmptyCollections {
+
+ public List names() {
+ if (userExist()) {
+ return Stream.of(readName()).collect(Collectors.toList());
+ } else {
+ return Collections.emptyList();
+ }
+ }
+
+ private boolean userExist() {
+ return false;
+ }
+
+ private String readName() {
+ return "test";
+ }
+}
diff --git a/patterns/design-patterns-2/src/main/java/com/baeldung/nulls/FindBugsAnnotations.java b/patterns/design-patterns-2/src/main/java/com/baeldung/nulls/FindBugsAnnotations.java
new file mode 100644
index 0000000000..697d5e4959
--- /dev/null
+++ b/patterns/design-patterns-2/src/main/java/com/baeldung/nulls/FindBugsAnnotations.java
@@ -0,0 +1,30 @@
+package com.baeldung.nulls;
+
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+
+public class FindBugsAnnotations {
+
+ public void accept(@NotNull Object param) {
+ System.out.println(param.toString());
+ }
+
+ public void print(@Nullable Object param) {
+ System.out.println("Printing " + param);
+ }
+
+ @NotNull
+ public Object process() throws Exception {
+ Object result = doSomething();
+ if (result == null) {
+ throw new Exception("Processing fail. Got a null response");
+ } else {
+ return result;
+ }
+ }
+
+ private Object doSomething() {
+ return null;
+ }
+}
diff --git a/patterns/design-patterns-2/src/main/java/com/baeldung/nulls/Preconditions.java b/patterns/design-patterns-2/src/main/java/com/baeldung/nulls/Preconditions.java
new file mode 100644
index 0000000000..9d9633a13e
--- /dev/null
+++ b/patterns/design-patterns-2/src/main/java/com/baeldung/nulls/Preconditions.java
@@ -0,0 +1,39 @@
+package com.baeldung.nulls;
+
+public class Preconditions {
+
+ public void goodAccept(String one, String two, String three) {
+ if (one == null || two == null || three == null) {
+ throw new IllegalArgumentException();
+ }
+
+ process(one);
+ process(two);
+ process(three);
+ }
+
+ public void badAccept(String one, String two, String three) {
+ if (one == null) {
+ throw new IllegalArgumentException();
+ } else {
+ process(one);
+ }
+
+ if (two == null) {
+ throw new IllegalArgumentException();
+ } else {
+ process(two);
+ }
+
+ if (three == null) {
+ throw new IllegalArgumentException();
+ } else {
+ process(three);
+ }
+
+ }
+
+ private void process(String one) {
+ }
+
+}
diff --git a/patterns/design-patterns-2/src/main/java/com/baeldung/nulls/PrimitivesAndWrapper.java b/patterns/design-patterns-2/src/main/java/com/baeldung/nulls/PrimitivesAndWrapper.java
new file mode 100644
index 0000000000..c75918c486
--- /dev/null
+++ b/patterns/design-patterns-2/src/main/java/com/baeldung/nulls/PrimitivesAndWrapper.java
@@ -0,0 +1,21 @@
+package com.baeldung.nulls;
+
+public class PrimitivesAndWrapper {
+
+ public static int primitiveSum(int a, int b) {
+ return a + b;
+ }
+
+ public static Integer wrapperSum(Integer a, Integer b) {
+ return a + b;
+ }
+
+ public static Integer goodSum(Integer a, Integer b) {
+ if (a != null && b != null) {
+ return a + b;
+ } else {
+ throw new IllegalArgumentException();
+ }
+ }
+
+}
diff --git a/patterns/design-patterns-2/src/main/java/com/baeldung/nulls/UsingLombok.java b/patterns/design-patterns-2/src/main/java/com/baeldung/nulls/UsingLombok.java
new file mode 100644
index 0000000000..73db0742c8
--- /dev/null
+++ b/patterns/design-patterns-2/src/main/java/com/baeldung/nulls/UsingLombok.java
@@ -0,0 +1,10 @@
+package com.baeldung.nulls;
+
+import lombok.NonNull;
+
+public class UsingLombok {
+
+ public void accept(@NonNull Object param){
+ System.out.println(param);
+ }
+}
diff --git a/patterns/design-patterns-2/src/main/java/com/baeldung/nulls/UsingObjects.java b/patterns/design-patterns-2/src/main/java/com/baeldung/nulls/UsingObjects.java
new file mode 100644
index 0000000000..5384edee5e
--- /dev/null
+++ b/patterns/design-patterns-2/src/main/java/com/baeldung/nulls/UsingObjects.java
@@ -0,0 +1,11 @@
+package com.baeldung.nulls;
+
+import java.util.Objects;
+
+public class UsingObjects {
+
+ public void accept(Object param) {
+ Objects.requireNonNull(param);
+ // doSomething()
+ }
+}
diff --git a/patterns/design-patterns-2/src/main/java/com/baeldung/nulls/UsingOptional.java b/patterns/design-patterns-2/src/main/java/com/baeldung/nulls/UsingOptional.java
new file mode 100644
index 0000000000..6c17290a72
--- /dev/null
+++ b/patterns/design-patterns-2/src/main/java/com/baeldung/nulls/UsingOptional.java
@@ -0,0 +1,27 @@
+package com.baeldung.nulls;
+
+import java.util.Optional;
+
+public class UsingOptional {
+
+ public Optional