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-dbutils.git

commit d81b49ad9c93766e13f3345c7137c1b89700148d
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Fri Mar 5 14:14:33 2021 -0500

    No need to nest in else.
---
 .../org/apache/commons/dbutils/BeanProcessor.java  |  5 ++---
 .../handlers/properties/DatePropertyHandler.java   |  4 ++--
 .../org/apache/commons/dbutils/MockResultSet.java  | 12 ++++++-----
 .../commons/dbutils/MockResultSetMetaData.java     | 18 +++++++++-------
 .../wrappers/SqlNullCheckedResultSetTest.java      | 24 ++++++++++++++--------
 5 files changed, 37 insertions(+), 26 deletions(-)

diff --git a/src/main/java/org/apache/commons/dbutils/BeanProcessor.java 
b/src/main/java/org/apache/commons/dbutils/BeanProcessor.java
index 7f76690..53c43eb 100644
--- a/src/main/java/org/apache/commons/dbutils/BeanProcessor.java
+++ b/src/main/java/org/apache/commons/dbutils/BeanProcessor.java
@@ -306,14 +306,13 @@ public class BeanProcessor {
             }
 
             // Don't call setter if the value object isn't the right type
-            if (this.isCompatibleType(value, firstParam)) {
-                setter.invoke(target, value);
-            } else {
+            if (!this.isCompatibleType(value, firstParam)) {
               throw new SQLException(
                   "Cannot set " + prop.getName() + ": incompatible types, 
cannot convert "
                   + value.getClass().getName() + " to " + 
firstParam.getName());
                   // value cannot be null here because isCompatibleType allows 
null
             }
+            setter.invoke(target, value);
 
         } catch (final IllegalArgumentException | IllegalAccessException | 
InvocationTargetException e) {
             throw new SQLException(
diff --git 
a/src/main/java/org/apache/commons/dbutils/handlers/properties/DatePropertyHandler.java
 
b/src/main/java/org/apache/commons/dbutils/handlers/properties/DatePropertyHandler.java
index 9f9e491..7360ed0 100644
--- 
a/src/main/java/org/apache/commons/dbutils/handlers/properties/DatePropertyHandler.java
+++ 
b/src/main/java/org/apache/commons/dbutils/handlers/properties/DatePropertyHandler.java
@@ -32,10 +32,10 @@ public class DatePropertyHandler implements PropertyHandler 
{
             final String targetType = parameter.getName();
             if ("java.sql.Date".equals(targetType)) {
                 return true;
-            } else
+            }
             if ("java.sql.Time".equals(targetType)) {
                 return true;
-            } else
+            }
             if ("java.sql.Timestamp".equals(targetType)
                     && !Timestamp.class.isInstance(value)) {
                 return true;
diff --git a/src/test/java/org/apache/commons/dbutils/MockResultSet.java 
b/src/test/java/org/apache/commons/dbutils/MockResultSet.java
index 537d4a3..66ad48e 100644
--- a/src/test/java/org/apache/commons/dbutils/MockResultSet.java
+++ b/src/test/java/org/apache/commons/dbutils/MockResultSet.java
@@ -82,12 +82,12 @@ public class MockResultSet implements InvocationHandler {
         if (args[0] instanceof Integer) {
             return ((Integer) args[0]).intValue();
 
-        } else if (args[0] instanceof String) {
+        }
+        if (args[0] instanceof String) {
             return this.columnNameToIndex((String) args[0]);
 
-        } else {
-            throw new SQLException(args[0] + " must be Integer or String");
         }
+        throw new SQLException(args[0] + " must be Integer or String");
     }
 
     /**
@@ -273,10 +273,12 @@ public class MockResultSet implements InvocationHandler {
         if (methodName.equals("getMetaData")) {
             return this.getMetaData();
 
-        } else if (methodName.equals("next")) {
+        }
+        if (methodName.equals("next")) {
             return this.next();
 
-        } else if (methodName.equals("previous")) {
+        }
+        if (methodName.equals("previous")) {
 
         } else if (methodName.equals("close")) {
 
diff --git 
a/src/test/java/org/apache/commons/dbutils/MockResultSetMetaData.java 
b/src/test/java/org/apache/commons/dbutils/MockResultSetMetaData.java
index dbcbe0d..04f0737 100644
--- a/src/test/java/org/apache/commons/dbutils/MockResultSetMetaData.java
+++ b/src/test/java/org/apache/commons/dbutils/MockResultSetMetaData.java
@@ -65,29 +65,33 @@ public class MockResultSetMetaData implements 
InvocationHandler {
         if (methodName.equals("getColumnCount")) {
             return Integer.valueOf(this.columnNames.length);
 
-        } else if (
+        }
+        if (
                 methodName.equals("getColumnName")) {
 
                 final int col = ((Integer) args[0]).intValue() - 1;
                 return this.columnNames[col];
 
-        } else if (
+        }
+        if (
                 methodName.equals("getColumnLabel")) {
 
                 final int col = ((Integer) args[0]).intValue() - 1;
                 return this.columnLabels[col];
 
-        } else if (methodName.equals("hashCode")) {
+        }
+        if (methodName.equals("hashCode")) {
             return Integer.valueOf(System.identityHashCode(proxy));
 
-        } else if (methodName.equals("toString")) {
+        }
+        if (methodName.equals("toString")) {
             return "MockResultSetMetaData " + System.identityHashCode(proxy);
 
-        } else if (methodName.equals("equals")) {
+        }
+        if (methodName.equals("equals")) {
             return Boolean.valueOf(proxy == args[0]);
 
-        } else {
-            throw new UnsupportedOperationException("Unsupported method: " + 
methodName);
         }
+        throw new UnsupportedOperationException("Unsupported method: " + 
methodName);
     }
 }
diff --git 
a/src/test/java/org/apache/commons/dbutils/wrappers/SqlNullCheckedResultSetTest.java
 
b/src/test/java/org/apache/commons/dbutils/wrappers/SqlNullCheckedResultSetTest.java
index b9e65fa..0269fe2 100644
--- 
a/src/test/java/org/apache/commons/dbutils/wrappers/SqlNullCheckedResultSetTest.java
+++ 
b/src/test/java/org/apache/commons/dbutils/wrappers/SqlNullCheckedResultSetTest.java
@@ -853,30 +853,36 @@ class SqlNullUncheckedMockResultSet implements 
InvocationHandler {
         if (method.getName().equals("wasNull")) {
             return Boolean.TRUE;
 
-        } else if (returnType.equals(Boolean.TYPE)) {
+        }
+        if (returnType.equals(Boolean.TYPE)) {
             return Boolean.FALSE;
 
-        } else if (returnType.equals(Integer.TYPE)) {
+        }
+        if (returnType.equals(Integer.TYPE)) {
             return Integer.valueOf(0);
 
-        } else if (returnType.equals(Short.TYPE)) {
+        }
+        if (returnType.equals(Short.TYPE)) {
             return Short.valueOf((short) 0);
 
-        } else if (returnType.equals(Double.TYPE)) {
+        }
+        if (returnType.equals(Double.TYPE)) {
             return new Double(0);
 
-        } else if (returnType.equals(Long.TYPE)) {
+        }
+        if (returnType.equals(Long.TYPE)) {
             return Long.valueOf(0);
 
-        } else if (returnType.equals(Byte.TYPE)) {
+        }
+        if (returnType.equals(Byte.TYPE)) {
             return Byte.valueOf((byte) 0);
 
-        } else if (returnType.equals(Float.TYPE)) {
+        }
+        if (returnType.equals(Float.TYPE)) {
             return new Float(0);
 
-        } else {
-            return null;
         }
+        return null;
     }
 }
 

Reply via email to