diff --git a/src/main/java/org/apache/commons/beanutils/BasicDynaBean.java b/src/main/java/org/apache/commons/beanutils/BasicDynaBean.java index 031e5efec..92e929d66 100644 --- a/src/main/java/org/apache/commons/beanutils/BasicDynaBean.java +++ b/src/main/java/org/apache/commons/beanutils/BasicDynaBean.java @@ -22,6 +22,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; /** *
Minimal implementation of the Implements Implements {@link DynaClass} to create an in-memory collection
@@ -198,17 +199,13 @@ public RowSetDynaClass(final ResultSet resultSet, final boolean lowerCase, final
* @since 1.8.3
*/
public RowSetDynaClass(final ResultSet resultSet, final boolean lowerCase, final int limit, final boolean useColumnLabel)
- throws SQLException {
-
- if (resultSet == null) {
- throw new NullPointerException();
- }
+ throws SQLException {
+ Objects.requireNonNull(resultSet, "resultSet");
this.lowerCase = lowerCase;
this.limit = limit;
setUseColumnLabel(useColumnLabel);
introspect(resultSet);
copy(resultSet);
-
}
/**
diff --git a/src/main/java/org/apache/commons/beanutils/converters/AbstractArrayConverter.java b/src/main/java/org/apache/commons/beanutils/converters/AbstractArrayConverter.java
index 96dbe01fb..1ffb35720 100644
--- a/src/main/java/org/apache/commons/beanutils/converters/AbstractArrayConverter.java
+++ b/src/main/java/org/apache/commons/beanutils/converters/AbstractArrayConverter.java
@@ -22,6 +22,7 @@
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
+import java.util.Objects;
import org.apache.commons.beanutils.ConversionException;
import org.apache.commons.beanutils.Converter;
@@ -135,55 +136,41 @@ public AbstractArrayConverter(final Object defaultValue) {
* is DynaBean
interface. Can be
@@ -80,18 +81,12 @@ public BasicDynaBean(final DynaClass dynaClass) {
*/
@Override
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);
}
- throw new IllegalArgumentException
- ("Non-mapped property for '" + name + "(" + key + ")'");
-
+ throw new IllegalArgumentException("Non-mapped property for '" + name + "(" + key + ")'");
}
/**
@@ -162,21 +157,15 @@ public Object get(final String name) {
*/
@Override
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);
}
if (value instanceof List) {
return ((List>) value).get(index);
}
- throw new IllegalArgumentException
- ("Non-indexed property for '" + name + "[" + index + "]'");
-
+ throw new IllegalArgumentException("Non-indexed property for '" + name + "[" + index + "]'");
}
/**
@@ -193,18 +182,12 @@ public Object get(final String name, final int index) {
*/
@Override
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);
}
- throw new IllegalArgumentException
- ("Non-mapped property for '" + name + "(" + key + ")'");
-
+ throw new IllegalArgumentException("Non-mapped property for '" + name + "(" + key + ")'");
}
/**
@@ -297,18 +280,12 @@ protected boolean isAssignable(final Class> dest, final Class> source) {
*/
@Override
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 + ")'");
+ throw new IllegalArgumentException("Non-mapped property for '" + name + "(" + key + ")'");
}
((Map, ?>) value).remove(key);
-
}
/**
@@ -330,10 +307,7 @@ public void remove(final String name, final String key) {
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) {
@@ -401,23 +375,18 @@ public void set(final String name, final Object value) {
*/
@Override
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 + ")'");
}
- @SuppressWarnings("unchecked")
- final
// This is safe to cast because mapped properties are always
// maps of types String -> Object
- MapDynaClass
for DynaBeans that wrap the
@@ -153,11 +154,7 @@ public ResultSetDynaClass(final ResultSet resultSet, final boolean lowerCase)
*/
public ResultSetDynaClass(final ResultSet resultSet, final boolean lowerCase, final boolean useColumnLabel)
throws SQLException {
-
- if (resultSet == null) {
- throw new NullPointerException();
- }
- this.resultSet = resultSet;
+ this.resultSet = Objects.requireNonNull(resultSet, "resultSet");
this.lowerCase = lowerCase;
setUseColumnLabel(useColumnLabel);
introspect(resultSet);
diff --git a/src/main/java/org/apache/commons/beanutils/RowSetDynaClass.java b/src/main/java/org/apache/commons/beanutils/RowSetDynaClass.java
index ecde68f57..b147508aa 100644
--- a/src/main/java/org/apache/commons/beanutils/RowSetDynaClass.java
+++ b/src/main/java/org/apache/commons/beanutils/RowSetDynaClass.java
@@ -21,6 +21,7 @@
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
+import java.util.Objects;
/**
* null
*/
protected List