You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2022/05/06 12:35:33 UTC

[commons-beanutils] branch master updated: Use Objects.requireNonNull()

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-beanutils.git


The following commit(s) were added to refs/heads/master by this push:
     new 5da1aaf1 Use Objects.requireNonNull()
5da1aaf1 is described below

commit 5da1aaf1132beda086608651edf869cf50a8ddba
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri May 6 08:35:28 2022 -0400

    Use Objects.requireNonNull()
---
 .../apache/commons/beanutils2/BasicDynaBean.java   | 31 +++++-----------------
 1 file changed, 7 insertions(+), 24 deletions(-)

diff --git a/src/main/java/org/apache/commons/beanutils2/BasicDynaBean.java b/src/main/java/org/apache/commons/beanutils2/BasicDynaBean.java
index 6ec11c6d..4217ab14 100644
--- a/src/main/java/org/apache/commons/beanutils2/BasicDynaBean.java
+++ b/src/main/java/org/apache/commons/beanutils2/BasicDynaBean.java
@@ -22,6 +22,7 @@ import java.lang.reflect.Array;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 
 /**
  * <p>Minimal implementation of the {@code DynaBean} interface.  Can be
@@ -117,10 +118,7 @@ public class BasicDynaBean implements DynaBean, Serializable {
     public boolean contains(final String name, final String key) {
 
         final Object value = values.get(name);
-        if (value == null) {
-            throw new NullPointerException
-                    ("No mapped value for '" + name + "(" + key + ")'");
-        }
+        Objects.requireNonNull(value, "No mapped value for '" + name + "(" + key + ")'");
         if (value instanceof Map) {
             return ((Map<?, ?>) value).containsKey(key);
         }
@@ -202,10 +200,7 @@ public class BasicDynaBean implements DynaBean, Serializable {
     public Object get(final String name, final int index) {
 
         final Object value = values.get(name);
-        if (value == null) {
-            throw new NullPointerException
-                    ("No indexed value for '" + name + "[" + index + "]'");
-        }
+        Objects.requireNonNull(value, "No indexed value for '" + name + "[" + index + "]'");
         if (value.getClass().isArray()) {
             return Array.get(value, index);
         }
@@ -234,10 +229,7 @@ public class BasicDynaBean implements DynaBean, Serializable {
     public Object get(final String name, final String key) {
 
         final Object value = values.get(name);
-        if (value == null) {
-            throw new NullPointerException
-                    ("No mapped value for '" + name + "(" + key + ")'");
-        }
+        Objects.requireNonNull(value, "No mapped value for '" + name + "(" + key + ")'");
         if (value instanceof Map) {
             return ((Map<?, ?>) value).get(key);
         }
@@ -274,10 +266,7 @@ public class BasicDynaBean implements DynaBean, Serializable {
     public void remove(final String name, final String key) {
 
         final Object value = values.get(name);
-        if (value == null) {
-            throw new NullPointerException
-                    ("No mapped value for '" + name + "(" + key + ")'");
-        }
+        Objects.requireNonNull(value, "No mapped value for '" + name + "(" + key + ")'");
         if (!(value instanceof Map)) {
             throw new IllegalArgumentException
                     ("Non-mapped property for '" + name + "(" + key + ")'");
@@ -339,10 +328,7 @@ public class BasicDynaBean implements DynaBean, Serializable {
     public void set(final String name, final int index, final Object value) {
 
         final Object prop = values.get(name);
-        if (prop == null) {
-            throw new NullPointerException
-                    ("No indexed value for '" + name + "[" + index + "]'");
-        }
+        Objects.requireNonNull(prop, "No indexed value for '" + name + "[" + index + "]'");
         if (prop.getClass().isArray()) {
             Array.set(prop, index, value);
         } else if (prop instanceof List) {
@@ -381,10 +367,7 @@ public class BasicDynaBean implements DynaBean, Serializable {
     public void set(final String name, final String key, final Object value) {
 
         final Object prop = values.get(name);
-        if (prop == null) {
-            throw new NullPointerException
-                    ("No mapped value for '" + name + "(" + key + ")'");
-        }
+        Objects.requireNonNull(prop, "No mapped value for '" + name + "(" + key + ")'");
         if (!(prop instanceof Map)) {
             throw new IllegalArgumentException
                     ("Non-mapped property for '" + name + "(" + key + ")'");