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 2020/11/21 02:55:10 UTC

[commons-validator] 02/02: No need to initialize to default value.

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

commit 17081b6fa0a097325bf52a05a706423876bb0655
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Nov 20 21:55:04 2020 -0500

    No need to initialize to default value.
---
 .../routines/AbstractCalendarValidator.java        |  4 +--
 .../commons/validator/AbstractNumberTest.java      |  4 +--
 .../org/apache/commons/validator/DateTest.java     |  4 +--
 .../org/apache/commons/validator/EmailTest.java    |  4 +--
 .../apache/commons/validator/ExtensionTest.java    | 28 +++++--------------
 .../validator/GenericTypeValidatorTest.java        |  8 ++----
 .../commons/validator/GenericValidatorImpl.java    |  3 +-
 .../org/apache/commons/validator/LocaleTest.java   |  4 +--
 .../commons/validator/MultipleConfigFilesTest.java | 16 +++--------
 .../org/apache/commons/validator/MultipleTest.java | 32 ++++++----------------
 .../apache/commons/validator/RequiredIfTest.java   | 20 ++++----------
 .../apache/commons/validator/RequiredNameTest.java | 24 ++++------------
 .../apache/commons/validator/ValidatorTest.java    |  3 +-
 .../validator/routines/CodeValidatorTest.java      |  2 +-
 .../validator/routines/TimeValidatorTest.java      |  2 +-
 15 files changed, 42 insertions(+), 116 deletions(-)

diff --git a/src/main/java/org/apache/commons/validator/routines/AbstractCalendarValidator.java b/src/main/java/org/apache/commons/validator/routines/AbstractCalendarValidator.java
index 48d5ff1..14f9b92 100644
--- a/src/main/java/org/apache/commons/validator/routines/AbstractCalendarValidator.java
+++ b/src/main/java/org/apache/commons/validator/routines/AbstractCalendarValidator.java
@@ -273,7 +273,7 @@ public abstract class AbstractCalendarValidator extends AbstractFormatValidator
      */
     protected int compare(Calendar value, Calendar compare, int field) {
 
-        int result = 0;
+        int result;
 
         // Compare Year
         result = calculateCompareResult(value, compare, Calendar.YEAR);
@@ -329,7 +329,7 @@ public abstract class AbstractCalendarValidator extends AbstractFormatValidator
      */
     protected int compareTime(Calendar value, Calendar compare, int field) {
 
-        int result = 0;
+        int result;
 
         // Compare Hour
         result = calculateCompareResult(value, compare, Calendar.HOUR_OF_DAY);
diff --git a/src/test/java/org/apache/commons/validator/AbstractNumberTest.java b/src/test/java/org/apache/commons/validator/AbstractNumberTest.java
index 0b2f6b7..125edaf 100644
--- a/src/test/java/org/apache/commons/validator/AbstractNumberTest.java
+++ b/src/test/java/org/apache/commons/validator/AbstractNumberTest.java
@@ -91,13 +91,11 @@ abstract public class AbstractNumberTest extends AbstractCommonTest {
         validator.setParameter(Validator.BEAN_PARAM, info);
 
         // Get results of the validation.
-        ValidatorResults results = null;
-
         // throws ValidatorException,
         // but we aren't catching for testing
         // since no validation methods we use
         // throw this
-        results = validator.validate();
+        ValidatorResults results = validator.validate();
 
         assertNotNull("Results are null.", results);
 
diff --git a/src/test/java/org/apache/commons/validator/DateTest.java b/src/test/java/org/apache/commons/validator/DateTest.java
index 79539d3..b8f2c62 100644
--- a/src/test/java/org/apache/commons/validator/DateTest.java
+++ b/src/test/java/org/apache/commons/validator/DateTest.java
@@ -91,13 +91,11 @@ public class DateTest extends AbstractCommonTest {
         validator.setParameter(Validator.LOCALE_PARAM, Locale.US);
 
         // Get results of the validation.
-        ValidatorResults results = null;
-
         // throws ValidatorException,
         // but we aren't catching for testing
         // since no validation methods we use
         // throw this
-        results = validator.validate();
+        ValidatorResults results = validator.validate();
 
         assertNotNull("Results are null.", results);
 
diff --git a/src/test/java/org/apache/commons/validator/EmailTest.java b/src/test/java/org/apache/commons/validator/EmailTest.java
index 1216bd8..dbcb576 100644
--- a/src/test/java/org/apache/commons/validator/EmailTest.java
+++ b/src/test/java/org/apache/commons/validator/EmailTest.java
@@ -430,13 +430,11 @@ protected void setUp() throws IOException, SAXException {
       validator.setParameter(Validator.BEAN_PARAM, info);
 
       // Get results of the validation.
-      ValidatorResults results = null;
-      
       // throws ValidatorException, 
       // but we aren't catching for testing 
       // since no validation methods we use 
       // throw this
-      results = validator.validate();
+      ValidatorResults results = validator.validate();
       
       assertNotNull("Results are null.", results);
       
diff --git a/src/test/java/org/apache/commons/validator/ExtensionTest.java b/src/test/java/org/apache/commons/validator/ExtensionTest.java
index 38301ab..8658322 100644
--- a/src/test/java/org/apache/commons/validator/ExtensionTest.java
+++ b/src/test/java/org/apache/commons/validator/ExtensionTest.java
@@ -104,13 +104,11 @@ public class ExtensionTest extends TestCase {
        validator.setParameter(Validator.BEAN_PARAM, name);
 
        // Get results of the validation.
-       ValidatorResults results = null;
-
        // throws ValidatorException,
        // but we aren't catching for testing
        // since no validation methods we use
        // throw this
-       results = validator.validate();
+       ValidatorResults results = validator.validate();
 
        assertNotNull("Results are null.", results);
 
@@ -142,9 +140,7 @@ public class ExtensionTest extends TestCase {
        validator.setParameter(Validator.BEAN_PARAM, name);
 
        // Get results of the validation.
-       ValidatorResults results = null;
-
-       results = validator.validate();
+       ValidatorResults results = validator.validate();
 
        assertNotNull("Results are null.", results);
 
@@ -176,9 +172,7 @@ public class ExtensionTest extends TestCase {
        validator.setParameter(Validator.BEAN_PARAM, name);
 
        // Get results of the validation.
-       ValidatorResults results = null;
-
-       results = validator.validate();
+       ValidatorResults results = validator.validate();
 
        assertNotNull("Results are null.", results);
 
@@ -210,9 +204,7 @@ public class ExtensionTest extends TestCase {
        validator.setParameter(Validator.BEAN_PARAM, name);
 
        // Get results of the validation.
-       ValidatorResults results = null;
-
-       results = validator.validate();
+       ValidatorResults results = validator.validate();
 
        assertNotNull("Results are null.", results);
 
@@ -244,9 +236,7 @@ public class ExtensionTest extends TestCase {
        validator.setParameter(Validator.BEAN_PARAM, name);
 
        // Get results of the validation.
-       ValidatorResults results = null;
-
-       results = validator.validate();
+       ValidatorResults results = validator.validate();
 
        assertNotNull("Results are null.", results);
 
@@ -280,9 +270,7 @@ public class ExtensionTest extends TestCase {
        validator.setParameter(Validator.BEAN_PARAM, name);
 
        // Get results of the validation.
-       ValidatorResults results = null;
-
-       results = validator.validate();
+       ValidatorResults results = validator.validate();
 
        assertNotNull("Results are null.", results);
 
@@ -317,9 +305,7 @@ public class ExtensionTest extends TestCase {
        validator.setParameter(Validator.BEAN_PARAM, name);
 
        // Get results of the validation.
-       ValidatorResults results = null;
-
-       results = validator.validate();
+       ValidatorResults results = validator.validate();
 
        assertNotNull("Results are null.", results);
 
diff --git a/src/test/java/org/apache/commons/validator/GenericTypeValidatorTest.java b/src/test/java/org/apache/commons/validator/GenericTypeValidatorTest.java
index 6014a55..da6d45d 100644
--- a/src/test/java/org/apache/commons/validator/GenericTypeValidatorTest.java
+++ b/src/test/java/org/apache/commons/validator/GenericTypeValidatorTest.java
@@ -81,13 +81,11 @@ protected void tearDown() {
       validator.setParameter(Validator.BEAN_PARAM, info);
 
       // Get results of the validation.
-      ValidatorResults results = null;
-      
       // throws ValidatorException, 
       // but we aren't catching for testing 
       // since no validation methods we use 
       // throw this
-      results = validator.validate();
+      ValidatorResults results = validator.validate();
       
       assertNotNull("Results are null.", results);
       
@@ -163,13 +161,11 @@ protected void tearDown() {
       validator.setParameter("java.util.Locale", locale);
 
       // Get results of the validation.
-      ValidatorResults results = null;
-      
       // throws ValidatorException, 
       // but we aren't catching for testing 
       // since no validation methods we use 
       // throw this
-      results = validator.validate();
+      ValidatorResults results = validator.validate();
       
       assertNotNull("Results are null.", results);
       
diff --git a/src/test/java/org/apache/commons/validator/GenericValidatorImpl.java b/src/test/java/org/apache/commons/validator/GenericValidatorImpl.java
index 9eb7b86..7af59e3 100644
--- a/src/test/java/org/apache/commons/validator/GenericValidatorImpl.java
+++ b/src/test/java/org/apache/commons/validator/GenericValidatorImpl.java
@@ -221,7 +221,6 @@ public class GenericValidatorImpl {
             if (dependIndexed == null) {
                 dependIndexed = "false";
             }
-            String dependVal = null;
             boolean this_required = false;
             if (field.isIndexed() && dependIndexed.equalsIgnoreCase("true")) {
                 String key = field.getKey();
@@ -230,7 +229,7 @@ public class GenericValidatorImpl {
                     dependProp = ind + dependProp;
                 }
             }
-            dependVal = ValidatorUtils.getValueAsString(form, dependProp);
+            String dependVal = ValidatorUtils.getValueAsString(form, dependProp);
             if (dependTest.equals(FIELD_TEST_NULL)) {
                 if ((dependVal != null) && (dependVal.length() > 0)) {
                     this_required = false;
diff --git a/src/test/java/org/apache/commons/validator/LocaleTest.java b/src/test/java/org/apache/commons/validator/LocaleTest.java
index 95c933a..2d9cda4 100644
--- a/src/test/java/org/apache/commons/validator/LocaleTest.java
+++ b/src/test/java/org/apache/commons/validator/LocaleTest.java
@@ -164,13 +164,11 @@ public class LocaleTest extends AbstractCommonTest {
         validator.setParameter(Validator.BEAN_PARAM, name);
         validator.setParameter(Validator.LOCALE_PARAM, loc);
         // Get results of the validation.
-        ValidatorResults results = null;
-
         // throws ValidatorException,
         // but we aren't catching for testing
         // since no validation methods we use
         // throw this
-        results = validator.validate();
+        ValidatorResults results = validator.validate();
 
         assertNotNull("Results are null.", results);
 
diff --git a/src/test/java/org/apache/commons/validator/MultipleConfigFilesTest.java b/src/test/java/org/apache/commons/validator/MultipleConfigFilesTest.java
index 67bef7f..7d08082 100644
--- a/src/test/java/org/apache/commons/validator/MultipleConfigFilesTest.java
+++ b/src/test/java/org/apache/commons/validator/MultipleConfigFilesTest.java
@@ -136,13 +136,11 @@ public class MultipleConfigFilesTest extends TestCase {
         validator.setParameter(Validator.BEAN_PARAM, name);
 
         // Get results of the validation.
-        ValidatorResults results = null;
-
         // throws ValidatorException,
         // but we aren't catching for testing
         // since no validation methods we use
         // throw this
-        results = validator.validate();
+        ValidatorResults results = validator.validate();
 
         assertNotNull("Results are null.", results);
 
@@ -177,9 +175,7 @@ public class MultipleConfigFilesTest extends TestCase {
         validator.setParameter(Validator.BEAN_PARAM, name);
 
         // Get results of the validation.
-        ValidatorResults results = null;
-
-        results = validator.validate();
+        ValidatorResults results = validator.validate();
 
         assertNotNull("Results are null.", results);
 
@@ -212,9 +208,7 @@ public class MultipleConfigFilesTest extends TestCase {
         validator.setParameter(Validator.BEAN_PARAM, name);
 
         // Get results of the validation.
-        ValidatorResults results = null;
-
-        results = validator.validate();
+        ValidatorResults results = validator.validate();
 
         assertNotNull("Results are null.", results);
 
@@ -247,9 +241,7 @@ public class MultipleConfigFilesTest extends TestCase {
         validator.setParameter(Validator.BEAN_PARAM, name);
 
         // Get results of the validation.
-        ValidatorResults results = null;
-
-        results = validator.validate();
+        ValidatorResults results = validator.validate();
 
         assertNotNull("Results are null.", results);
 
diff --git a/src/test/java/org/apache/commons/validator/MultipleTest.java b/src/test/java/org/apache/commons/validator/MultipleTest.java
index b6d6446..903df62 100644
--- a/src/test/java/org/apache/commons/validator/MultipleTest.java
+++ b/src/test/java/org/apache/commons/validator/MultipleTest.java
@@ -73,13 +73,11 @@ protected void tearDown() {
       validator.setParameter(Validator.BEAN_PARAM, name);
 
       // Get results of the validation.
-      ValidatorResults results = null;
-
       // throws ValidatorException,
       // but we aren't catching for testing
       // since no validation methods we use
       // throw this
-      results = validator.validate();
+      ValidatorResults results = validator.validate();
 
       assertNotNull("Results are null.", results);
 
@@ -113,9 +111,7 @@ protected void tearDown() {
       validator.setParameter(Validator.BEAN_PARAM, name);
 
       // Get results of the validation.
-      ValidatorResults results = null;
-
-      results = validator.validate();
+      ValidatorResults results = validator.validate();
 
       assertNotNull("Results are null.", results);
 
@@ -148,9 +144,7 @@ protected void tearDown() {
       validator.setParameter(Validator.BEAN_PARAM, name);
 
       // Get results of the validation.
-      ValidatorResults results = null;
-
-      results = validator.validate();
+      ValidatorResults results = validator.validate();
 
       assertNotNull("Results are null.", results);
 
@@ -183,9 +177,7 @@ protected void tearDown() {
       validator.setParameter(Validator.BEAN_PARAM, name);
 
       // Get results of the validation.
-      ValidatorResults results = null;
-
-      results = validator.validate();
+      ValidatorResults results = validator.validate();
 
       assertNotNull("Results are null.", results);
 
@@ -219,9 +211,7 @@ protected void tearDown() {
        validator.setParameter(Validator.BEAN_PARAM, name);
 
        // Get results of the validation.
-       ValidatorResults results = null;
-
-       results = validator.validate();
+       ValidatorResults results = validator.validate();
 
        assertNotNull("Results are null.", results);
 
@@ -257,9 +247,7 @@ protected void tearDown() {
        validator.setParameter(Validator.BEAN_PARAM, name);
 
        // Get results of the validation.
-       ValidatorResults results = null;
-
-       results = validator.validate();
+       ValidatorResults results = validator.validate();
 
        assertNotNull("Results are null.", results);
 
@@ -295,9 +283,7 @@ protected void tearDown() {
        validator.setParameter(Validator.BEAN_PARAM, name);
 
        // Get results of the validation.
-       ValidatorResults results = null;
-
-       results = validator.validate();
+       ValidatorResults results = validator.validate();
 
        assertNotNull("Results are null.", results);
 
@@ -334,9 +320,7 @@ protected void tearDown() {
        validator.setParameter(Validator.BEAN_PARAM, name);
 
        // Get results of the validation.
-       ValidatorResults results = null;
-
-       results = validator.validate();
+       ValidatorResults results = validator.validate();
 
        assertNotNull("Results are null.", results);
 
diff --git a/src/test/java/org/apache/commons/validator/RequiredIfTest.java b/src/test/java/org/apache/commons/validator/RequiredIfTest.java
index 48162fb..a40602b 100644
--- a/src/test/java/org/apache/commons/validator/RequiredIfTest.java
+++ b/src/test/java/org/apache/commons/validator/RequiredIfTest.java
@@ -72,13 +72,11 @@ protected void tearDown() {
       validator.setParameter(Validator.BEAN_PARAM, name);
 
       // Get results of the validation.
-      ValidatorResults results = null;
-      
       // throws ValidatorException, 
       // but we aren't catching for testing 
       // since no validation methods we use 
       // throw this
-      results = validator.validate();
+      ValidatorResults results = validator.validate();
       
       assertNotNull("Results are null.", results);
       
@@ -111,9 +109,7 @@ protected void tearDown() {
       validator.setParameter(Validator.BEAN_PARAM, name);
 
       // Get results of the validation.
-      ValidatorResults results = null;
-      
-      results = validator.validate();
+      ValidatorResults results = validator.validate();
       
       assertNotNull("Results are null.", results);
       
@@ -146,9 +142,7 @@ protected void tearDown() {
       validator.setParameter(Validator.BEAN_PARAM, name);
 
       // Get results of the validation.
-      ValidatorResults results = null;
-      
-      results = validator.validate();
+      ValidatorResults results = validator.validate();
       
       assertNotNull("Results are null.", results);
       
@@ -181,9 +175,7 @@ protected void tearDown() {
       validator.setParameter(Validator.BEAN_PARAM, name);
 
       // Get results of the validation.
-      ValidatorResults results = null;
-      
-      results = validator.validate();
+      ValidatorResults results = validator.validate();
       
       assertNotNull("Results are null.", results);
       
@@ -216,9 +208,7 @@ protected void tearDown() {
       validator.setParameter(Validator.BEAN_PARAM, name);
 
       // Get results of the validation.
-      ValidatorResults results = null;
-      
-      results = validator.validate();
+      ValidatorResults results = validator.validate();
       
       assertNotNull("Results are null.", results);
       
diff --git a/src/test/java/org/apache/commons/validator/RequiredNameTest.java b/src/test/java/org/apache/commons/validator/RequiredNameTest.java
index 94637b8..01d267d 100644
--- a/src/test/java/org/apache/commons/validator/RequiredNameTest.java
+++ b/src/test/java/org/apache/commons/validator/RequiredNameTest.java
@@ -72,13 +72,11 @@ protected void tearDown() {
       validator.setParameter(Validator.BEAN_PARAM, name);
 
       // Get results of the validation.
-      ValidatorResults results = null;
-      
       // throws ValidatorException, 
       // but we aren't catching for testing 
       // since no validation methods we use 
       // throw this
-      results = validator.validate();
+      ValidatorResults results = validator.validate();
       
       assertNotNull("Results are null.", results);
       
@@ -110,9 +108,7 @@ protected void tearDown() {
       validator.setParameter(Validator.BEAN_PARAM, name);
 
       // Get results of the validation.
-      ValidatorResults results = null;
-      
-      results = validator.validate();
+      ValidatorResults results = validator.validate();
       
       assertNotNull("Results are null.", results);
       
@@ -144,9 +140,7 @@ protected void tearDown() {
       validator.setParameter(Validator.BEAN_PARAM, name);
 
       // Get results of the validation.
-      ValidatorResults results = null;
-      
-      results = validator.validate();
+      ValidatorResults results = validator.validate();
       
       assertNotNull("Results are null.", results);
       
@@ -178,9 +172,7 @@ protected void tearDown() {
       validator.setParameter(Validator.BEAN_PARAM, name);
 
       // Get results of the validation.
-      ValidatorResults results = null;
-      
-      results = validator.validate();
+      ValidatorResults results = validator.validate();
       
       assertNotNull("Results are null.", results);
       
@@ -212,9 +204,7 @@ protected void tearDown() {
       validator.setParameter(Validator.BEAN_PARAM, name);
 
       // Get results of the validation.
-      ValidatorResults results = null;
-      
-      results = validator.validate();
+      ValidatorResults results = validator.validate();
       
       assertNotNull("Results are null.", results);
       
@@ -248,9 +238,7 @@ protected void tearDown() {
       validator.setParameter(Validator.BEAN_PARAM, name);
 
       // Get results of the validation.
-      ValidatorResults results = null;
-      
-      results = validator.validate();
+      ValidatorResults results = validator.validate();
       
       assertNotNull("Results are null.", results);
       
diff --git a/src/test/java/org/apache/commons/validator/ValidatorTest.java b/src/test/java/org/apache/commons/validator/ValidatorTest.java
index aa508c2..3ec8734 100644
--- a/src/test/java/org/apache/commons/validator/ValidatorTest.java
+++ b/src/test/java/org/apache/commons/validator/ValidatorTest.java
@@ -249,8 +249,7 @@ public class ValidatorTest extends TestCase {
       Date date = null;
       
       try {
-         DateFormat formatter = null;
-         formatter = DateFormat.getDateInstance(DateFormat.SHORT, Locale.US);
+          DateFormat formatter = DateFormat.getDateInstance(DateFormat.SHORT, Locale.US);
             
          formatter.setLenient(false);
              
diff --git a/src/test/java/org/apache/commons/validator/routines/CodeValidatorTest.java b/src/test/java/org/apache/commons/validator/routines/CodeValidatorTest.java
index 29d79dd..a23da74 100644
--- a/src/test/java/org/apache/commons/validator/routines/CodeValidatorTest.java
+++ b/src/test/java/org/apache/commons/validator/routines/CodeValidatorTest.java
@@ -213,7 +213,7 @@ public class CodeValidatorTest extends TestCase {
      * Test Regular Expression.
      */
     public void testConstructors() {
-        CodeValidator validator = null;
+        CodeValidator validator;
         RegexValidator regex = new RegexValidator("^[0-9]*$");
 
         // Constructor 1
diff --git a/src/test/java/org/apache/commons/validator/routines/TimeValidatorTest.java b/src/test/java/org/apache/commons/validator/routines/TimeValidatorTest.java
index aabc942..4bdc7e2 100644
--- a/src/test/java/org/apache/commons/validator/routines/TimeValidatorTest.java
+++ b/src/test/java/org/apache/commons/validator/routines/TimeValidatorTest.java
@@ -185,7 +185,7 @@ public class TimeValidatorTest extends TestCase {
         Locale.setDefault(Locale.UK);
         TimeZone.setDefault(GMT);
 
-        Calendar result = null;
+        Calendar result;
 
         // Default Locale, Default TimeZone
         result = validator.validate("18:01");