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/07/05 14:26:00 UTC

[commons-lang] branch master updated (a588f7e69 -> 6001ae8a0)

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

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


    from a588f7e69 Javadoc: StringUtils.repeat("", "x", 3) = "xx"; #918
     new aae5a3522 Use Objects#requireNonNull()
     new 7ee27499f Better internal exception handling.
     new fa3803095 Use Objects#requireNonNull()
     new 5cd20a04a Internal refactoring around private modify() method
     new 2073de145 Reuse our DateUtils#toCalendar(Date) API
     new 28b11d15e Javadoc
     new 827f5c93d Remove useless inline comments
     new edbaebb4d Clean up inline comments
     new 6001ae8a0 Add SystemUtils.IS_JAVA_17

The 9 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/changes/changes.xml                            |   1 +
 .../java/org/apache/commons/lang3/ArrayUtils.java  |   7 +-
 .../java/org/apache/commons/lang3/SystemUtils.java |  13 +-
 .../java/org/apache/commons/lang3/Validate.java    |   6 -
 .../lang3/exception/CloneFailedException.java      |   3 -
 .../commons/lang3/exception/ExceptionUtils.java    |   7 +-
 .../apache/commons/lang3/text/StrSubstitutor.java  |  29 +--
 .../text/translate/CharSequenceTranslator.java     |  18 +-
 .../org/apache/commons/lang3/time/DateUtils.java   | 230 ++++++++-------------
 .../apache/commons/lang3/time/FastDatePrinter.java |   2 +-
 .../org/apache/commons/lang3/ArrayUtilsTest.java   |   2 +-
 .../commons/lang3/StringEscapeUtilsTest.java       |  24 +--
 .../org/apache/commons/lang3/SystemUtilsTest.java  |  29 +++
 .../lang3/exception/ExceptionUtilsTest.java        |   2 +-
 .../commons/lang3/text/StrSubstitutorTest.java     |   8 +-
 .../commons/lang3/time/DateUtilsFragmentTest.java  |  48 +----
 .../apache/commons/lang3/time/DateUtilsTest.java   |  55 +++--
 17 files changed, 205 insertions(+), 279 deletions(-)


[commons-lang] 01/09: Use Objects#requireNonNull()

Posted by gg...@apache.org.
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-lang.git

commit aae5a3522fd585513693d6c550044247eae28a51
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Jul 5 09:00:04 2022 -0400

    Use Objects#requireNonNull()
---
 .../java/org/apache/commons/lang3/ArrayUtils.java  |  7 ++-----
 .../commons/lang3/exception/ExceptionUtils.java    |  7 +++----
 .../text/translate/CharSequenceTranslator.java     | 15 +++++++-------
 .../org/apache/commons/lang3/ArrayUtilsTest.java   |  2 +-
 .../commons/lang3/StringEscapeUtilsTest.java       | 24 +++++++++++-----------
 .../lang3/exception/ExceptionUtilsTest.java        |  2 +-
 6 files changed, 26 insertions(+), 31 deletions(-)

diff --git a/src/main/java/org/apache/commons/lang3/ArrayUtils.java b/src/main/java/org/apache/commons/lang3/ArrayUtils.java
index a098b0d5b..f0a698f3c 100644
--- a/src/main/java/org/apache/commons/lang3/ArrayUtils.java
+++ b/src/main/java/org/apache/commons/lang3/ArrayUtils.java
@@ -26,6 +26,7 @@ import java.util.Comparator;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Random;
 import java.util.concurrent.ThreadLocalRandom;
 import java.util.function.IntFunction;
@@ -3794,14 +3795,10 @@ public class ArrayUtils {
      * @since 3.4
      */
     public static <T> boolean isSorted(final T[] array, final Comparator<T> comparator) {
-        if (comparator == null) {
-            throw new IllegalArgumentException("Comparator should not be null.");
-        }
-
+        Objects.requireNonNull(comparator, "comparator");
         if (array == null || array.length < 2) {
             return true;
         }
-
         T previous = array[0];
         final int n = array.length;
         for (int i = 1; i < n; i++) {
diff --git a/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java b/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java
index 4de719fc3..2c3fa8531 100644
--- a/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java
+++ b/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java
@@ -716,13 +716,12 @@ public class ExceptionUtils {
      *
      * @param causeFrames  stack trace of a cause throwable
      * @param wrapperFrames  stack trace of a wrapper throwable
-     * @throws IllegalArgumentException if either argument is null
+     * @throws NullPointerException if either argument is null
      * @since 2.0
      */
     public static void removeCommonFrames(final List<String> causeFrames, final List<String> wrapperFrames) {
-        if (causeFrames == null || wrapperFrames == null) {
-            throw new IllegalArgumentException("The List must not be null");
-        }
+        Objects.requireNonNull(causeFrames, "causeFrames");
+        Objects.requireNonNull(wrapperFrames, "wrapperFrames");
         int causeFrameIndex = causeFrames.size() - 1;
         int wrapperFrameIndex = wrapperFrames.size() - 1;
         while (causeFrameIndex >= 0 && wrapperFrameIndex >= 0) {
diff --git a/src/main/java/org/apache/commons/lang3/text/translate/CharSequenceTranslator.java b/src/main/java/org/apache/commons/lang3/text/translate/CharSequenceTranslator.java
index 3c30ff064..373a3d5be 100644
--- a/src/main/java/org/apache/commons/lang3/text/translate/CharSequenceTranslator.java
+++ b/src/main/java/org/apache/commons/lang3/text/translate/CharSequenceTranslator.java
@@ -20,6 +20,7 @@ import java.io.IOException;
 import java.io.StringWriter;
 import java.io.Writer;
 import java.util.Locale;
+import java.util.Objects;
 
 /**
  * An API for translating text.
@@ -74,30 +75,28 @@ public abstract class CharSequenceTranslator {
      * tightly coupled with the abstract method of this class.
      *
      * @param input CharSequence that is being translated
-     * @param out Writer to translate the text to
+     * @param writer Writer to translate the text to
      * @throws IOException if and only if the Writer produces an IOException
      */
-    public final void translate(final CharSequence input, final Writer out) throws IOException {
-        if (out == null) {
-            throw new IllegalArgumentException("The Writer must not be null");
-        }
+    public final void translate(final CharSequence input, final Writer writer) throws IOException {
+        Objects.requireNonNull(writer, "writer");
         if (input == null) {
             return;
         }
         int pos = 0;
         final int len = input.length();
         while (pos < len) {
-            final int consumed = translate(input, pos, out);
+            final int consumed = translate(input, pos, writer);
             if (consumed == 0) {
                 // inlined implementation of Character.toChars(Character.codePointAt(input, pos))
                 // avoids allocating temp char arrays and duplicate checks
                 final char c1 = input.charAt(pos);
-                out.write(c1);
+                writer.write(c1);
                 pos++;
                 if (Character.isHighSurrogate(c1) && pos < len) {
                     final char c2 = input.charAt(pos);
                     if (Character.isLowSurrogate(c2)) {
-                      out.write(c2);
+                      writer.write(c2);
                       pos++;
                     }
                 }
diff --git a/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java b/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java
index c44419d7a..23a37bac1 100644
--- a/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java
@@ -1646,7 +1646,7 @@ public class ArrayUtilsTest {
 
     @Test
     public void testIsSortedNullComparator() {
-        assertThrows(IllegalArgumentException.class, () -> ArrayUtils.isSorted(null, null));
+        assertThrows(NullPointerException.class, () -> ArrayUtils.isSorted(null, null));
     }
 
     @Test
diff --git a/src/test/java/org/apache/commons/lang3/StringEscapeUtilsTest.java b/src/test/java/org/apache/commons/lang3/StringEscapeUtilsTest.java
index 80e04fbda..f6e1b44c1 100644
--- a/src/test/java/org/apache/commons/lang3/StringEscapeUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/StringEscapeUtilsTest.java
@@ -55,8 +55,8 @@ public class StringEscapeUtilsTest {
     @Test
     public void testEscapeJava() throws IOException {
         assertNull(StringEscapeUtils.escapeJava(null));
-        assertThrows(IllegalArgumentException.class, () -> StringEscapeUtils.ESCAPE_JAVA.translate(null, null));
-        assertThrows(IllegalArgumentException.class, () -> StringEscapeUtils.ESCAPE_JAVA.translate("", null));
+        assertThrows(NullPointerException.class, () -> StringEscapeUtils.ESCAPE_JAVA.translate(null, null));
+        assertThrows(NullPointerException.class, () -> StringEscapeUtils.ESCAPE_JAVA.translate("", null));
 
         assertEscapeJava("empty string", "", "");
         assertEscapeJava(FOO, FOO);
@@ -112,8 +112,8 @@ public class StringEscapeUtilsTest {
     @Test
     public void testUnescapeJava() throws IOException {
         assertNull(StringEscapeUtils.unescapeJava(null));
-        assertThrows(IllegalArgumentException.class, () -> StringEscapeUtils.UNESCAPE_JAVA.translate(null, null));
-        assertThrows(IllegalArgumentException.class, () -> StringEscapeUtils.UNESCAPE_JAVA.translate("", null));
+        assertThrows(NullPointerException.class, () -> StringEscapeUtils.UNESCAPE_JAVA.translate(null, null));
+        assertThrows(NullPointerException.class, () -> StringEscapeUtils.UNESCAPE_JAVA.translate("", null));
         assertThrows(RuntimeException.class, () -> StringEscapeUtils.unescapeJava("\\u02-3"));
 
         assertUnescapeJava("", "");
@@ -152,8 +152,8 @@ public class StringEscapeUtilsTest {
     @Test
     public void testEscapeEcmaScript() {
         assertNull(StringEscapeUtils.escapeEcmaScript(null));
-        assertThrows(IllegalArgumentException.class, () -> StringEscapeUtils.ESCAPE_ECMASCRIPT.translate(null, null));
-        assertThrows(IllegalArgumentException.class, () -> StringEscapeUtils.ESCAPE_ECMASCRIPT.translate("", null));
+        assertThrows(NullPointerException.class, () -> StringEscapeUtils.ESCAPE_ECMASCRIPT.translate(null, null));
+        assertThrows(NullPointerException.class, () -> StringEscapeUtils.ESCAPE_ECMASCRIPT.translate("", null));
 
         assertEquals("He didn\\'t say, \\\"stop!\\\"", StringEscapeUtils.escapeEcmaScript("He didn't say, \"stop!\""));
         assertEquals("document.getElementById(\\\"test\\\").value = \\'<script>alert(\\'aaa\\');<\\/script>\\';",
@@ -163,8 +163,8 @@ public class StringEscapeUtilsTest {
     @Test
     public void testUnescapeEcmaScript() {
         assertNull(StringEscapeUtils.escapeEcmaScript(null));
-        assertThrows(IllegalArgumentException.class, () -> StringEscapeUtils.UNESCAPE_ECMASCRIPT.translate(null, null));
-        assertThrows(IllegalArgumentException.class, () -> StringEscapeUtils.UNESCAPE_ECMASCRIPT.translate("", null));
+        assertThrows(NullPointerException.class, () -> StringEscapeUtils.UNESCAPE_ECMASCRIPT.translate(null, null));
+        assertThrows(NullPointerException.class, () -> StringEscapeUtils.UNESCAPE_ECMASCRIPT.translate("", null));
 
         assertEquals("He didn't say, \"stop!\"", StringEscapeUtils.unescapeEcmaScript("He didn\\'t say, \\\"stop!\\\""));
         assertEquals("document.getElementById(\"test\").value = '<script>alert('aaa');</script>';",
@@ -546,8 +546,8 @@ public class StringEscapeUtilsTest {
     @Test
     public void testEscapeJson() {
         assertNull(StringEscapeUtils.escapeJson(null));
-        assertThrows(IllegalArgumentException.class, () -> StringEscapeUtils.ESCAPE_JSON.translate(null, null));
-        assertThrows(IllegalArgumentException.class, () -> StringEscapeUtils.ESCAPE_JSON.translate("", null));
+        assertThrows(NullPointerException.class, () -> StringEscapeUtils.ESCAPE_JSON.translate(null, null));
+        assertThrows(NullPointerException.class, () -> StringEscapeUtils.ESCAPE_JSON.translate("", null));
 
         assertEquals("He didn't say, \\\"stop!\\\"", StringEscapeUtils.escapeJson("He didn't say, \"stop!\""));
 
@@ -560,8 +560,8 @@ public class StringEscapeUtilsTest {
     @Test
     public void testUnescapeJson() {
         assertNull(StringEscapeUtils.unescapeJson(null));
-        assertThrows(IllegalArgumentException.class, () -> StringEscapeUtils.UNESCAPE_JSON.translate(null, null));
-        assertThrows(IllegalArgumentException.class, () -> StringEscapeUtils.UNESCAPE_JSON.translate("", null));
+        assertThrows(NullPointerException.class, () -> StringEscapeUtils.UNESCAPE_JSON.translate(null, null));
+        assertThrows(NullPointerException.class, () -> StringEscapeUtils.UNESCAPE_JSON.translate("", null));
 
         assertEquals("He didn't say, \"stop!\"", StringEscapeUtils.unescapeJson("He didn't say, \\\"stop!\\\""));
 
diff --git a/src/test/java/org/apache/commons/lang3/exception/ExceptionUtilsTest.java b/src/test/java/org/apache/commons/lang3/exception/ExceptionUtilsTest.java
index ffe83c625..1b3747106 100644
--- a/src/test/java/org/apache/commons/lang3/exception/ExceptionUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/exception/ExceptionUtilsTest.java
@@ -666,7 +666,7 @@ public class ExceptionUtilsTest {
 
     @Test
     public void testRemoveCommonFrames_ListList() {
-        assertThrows(IllegalArgumentException.class, () -> ExceptionUtils.removeCommonFrames(null, null));
+        assertThrows(NullPointerException.class, () -> ExceptionUtils.removeCommonFrames(null, null));
     }
 
     @Test


[commons-lang] 02/09: Better internal exception handling.

Posted by gg...@apache.org.
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-lang.git

commit 7ee27499f8ddb1ff39e9736c90176c65654ec952
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Jul 5 09:04:55 2022 -0400

    Better internal exception handling.
---
 .../apache/commons/lang3/text/translate/CharSequenceTranslator.java    | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/lang3/text/translate/CharSequenceTranslator.java b/src/main/java/org/apache/commons/lang3/text/translate/CharSequenceTranslator.java
index 373a3d5be..f314cab73 100644
--- a/src/main/java/org/apache/commons/lang3/text/translate/CharSequenceTranslator.java
+++ b/src/main/java/org/apache/commons/lang3/text/translate/CharSequenceTranslator.java
@@ -18,6 +18,7 @@ package org.apache.commons.lang3.text.translate;
 
 import java.io.IOException;
 import java.io.StringWriter;
+import java.io.UncheckedIOException;
 import java.io.Writer;
 import java.util.Locale;
 import java.util.Objects;
@@ -66,7 +67,7 @@ public abstract class CharSequenceTranslator {
             return writer.toString();
         } catch (final IOException ioe) {
             // this should never ever happen while writing to a StringWriter
-            throw new RuntimeException(ioe);
+            throw new UncheckedIOException(ioe);
         }
     }
 


[commons-lang] 07/09: Remove useless inline comments

Posted by gg...@apache.org.
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-lang.git

commit 827f5c93df63d6b2300d2a87729c0911b4fc14f1
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Jul 5 10:12:57 2022 -0400

    Remove useless inline comments
---
 src/main/java/org/apache/commons/lang3/SystemUtils.java             | 3 ---
 src/main/java/org/apache/commons/lang3/Validate.java                | 6 ------
 .../org/apache/commons/lang3/exception/CloneFailedException.java    | 3 ---
 3 files changed, 12 deletions(-)

diff --git a/src/main/java/org/apache/commons/lang3/SystemUtils.java b/src/main/java/org/apache/commons/lang3/SystemUtils.java
index 7ba80be87..4a810cdc0 100644
--- a/src/main/java/org/apache/commons/lang3/SystemUtils.java
+++ b/src/main/java/org/apache/commons/lang3/SystemUtils.java
@@ -1561,7 +1561,6 @@ public class SystemUtils {
      */
     public static final boolean IS_OS_WINDOWS_XP = getOsMatchesName(OS_NAME_WINDOWS_PREFIX + " XP");
 
-    // -----------------------------------------------------------------------
     /**
      * <p>
      * Is {@code true} if this is Windows Vista.
@@ -1751,7 +1750,6 @@ public class SystemUtils {
         return isOSNameMatch(OS_NAME, osNamePrefix);
     }
 
-    // -----------------------------------------------------------------------
     /**
      * <p>
      * Gets a System property, defaulting to {@code null} if the property cannot be read.
@@ -1957,7 +1955,6 @@ public class SystemUtils {
         return true;
     }
 
-    // -----------------------------------------------------------------------
     /**
      * <p>
      * SystemUtils instances should NOT be constructed in standard programming. Instead, the class should be used as
diff --git a/src/main/java/org/apache/commons/lang3/Validate.java b/src/main/java/org/apache/commons/lang3/Validate.java
index 915c06997..8a5292e7a 100644
--- a/src/main/java/org/apache/commons/lang3/Validate.java
+++ b/src/main/java/org/apache/commons/lang3/Validate.java
@@ -220,9 +220,6 @@ public class Validate {
         return Objects.requireNonNull(object, () -> String.format(message, values));
     }
 
-    // notEmpty array
-    //---------------------------------------------------------------------------------
-
     /**
      * <p>Validate that the specified argument array is neither {@code null}
      * nor a length of zero (no elements); otherwise throwing an exception
@@ -1041,9 +1038,6 @@ public class Validate {
         }
     }
 
-    // exclusiveBetween
-    //---------------------------------------------------------------------------------
-
     /**
      * <p>Validate that the specified argument object fall between the two
      * exclusive values specified; otherwise, throws an exception.</p>
diff --git a/src/main/java/org/apache/commons/lang3/exception/CloneFailedException.java b/src/main/java/org/apache/commons/lang3/exception/CloneFailedException.java
index 5fff98ca2..7a4dcf26b 100644
--- a/src/main/java/org/apache/commons/lang3/exception/CloneFailedException.java
+++ b/src/main/java/org/apache/commons/lang3/exception/CloneFailedException.java
@@ -23,12 +23,9 @@ package org.apache.commons.lang3.exception;
  * @since 3.0
  */
 public class CloneFailedException extends RuntimeException {
-    // ~ Static fields/initializers ---------------------------------------------
 
     private static final long serialVersionUID = 20091223L;
 
-    // ~ Constructors -----------------------------------------------------------
-
     /**
      * Constructs a CloneFailedException.
      *


[commons-lang] 06/09: Javadoc

Posted by gg...@apache.org.
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-lang.git

commit 28b11d15e722760fd2f453e45517dce3f5124dec
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Jul 5 10:07:43 2022 -0400

    Javadoc
---
 src/main/java/org/apache/commons/lang3/time/FastDatePrinter.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/lang3/time/FastDatePrinter.java b/src/main/java/org/apache/commons/lang3/time/FastDatePrinter.java
index 229f4739c..ea6e682ba 100644
--- a/src/main/java/org/apache/commons/lang3/time/FastDatePrinter.java
+++ b/src/main/java/org/apache/commons/lang3/time/FastDatePrinter.java
@@ -469,7 +469,7 @@ public class FastDatePrinter implements DatePrinter, Serializable {
     }
 
     /**
-     * Creation method for new calender instances.
+     * Creates a new Calendar instance.
      * @return a new Calendar instance.
      */
     private Calendar newCalendar() {


[commons-lang] 03/09: Use Objects#requireNonNull()

Posted by gg...@apache.org.
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-lang.git

commit fa380309554ce4e0c1efdbec1e3b489444ecbf72
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Jul 5 09:44:44 2022 -0400

    Use Objects#requireNonNull()
---
 .../apache/commons/lang3/text/StrSubstitutor.java  |  29 ++--
 .../org/apache/commons/lang3/time/DateUtils.java   | 175 +++++++++------------
 .../commons/lang3/text/StrSubstitutorTest.java     |   8 +-
 .../commons/lang3/time/DateUtilsFragmentTest.java  |  48 ++----
 .../apache/commons/lang3/time/DateUtilsTest.java   |  55 +++----
 5 files changed, 122 insertions(+), 193 deletions(-)

diff --git a/src/main/java/org/apache/commons/lang3/text/StrSubstitutor.java b/src/main/java/org/apache/commons/lang3/text/StrSubstitutor.java
index 1f8c0a24f..b85c43e12 100644
--- a/src/main/java/org/apache/commons/lang3/text/StrSubstitutor.java
+++ b/src/main/java/org/apache/commons/lang3/text/StrSubstitutor.java
@@ -21,6 +21,7 @@ import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Properties;
 
 import org.apache.commons.lang3.StringUtils;
@@ -996,13 +997,10 @@ public class StrSubstitutor {
      *
      * @param prefixMatcher  the prefix matcher to use, null ignored
      * @return this, to enable chaining
-     * @throws IllegalArgumentException if the prefix matcher is null
+     * @throws NullPointerException if the prefix matcher is null
      */
     public StrSubstitutor setVariablePrefixMatcher(final StrMatcher prefixMatcher) {
-        if (prefixMatcher == null) {
-            throw new IllegalArgumentException("Variable prefix matcher must not be null.");
-        }
-        this.prefixMatcher = prefixMatcher;
+        this.prefixMatcher = Objects.requireNonNull(prefixMatcher, "prefixMatcher");
         return this;
     }
 
@@ -1030,13 +1028,10 @@ public class StrSubstitutor {
      *
      * @param prefix  the prefix for variables, not null
      * @return this, to enable chaining
-     * @throws IllegalArgumentException if the prefix is null
+     * @throws NullPointerException if the prefix is null
      */
     public StrSubstitutor setVariablePrefix(final String prefix) {
-       if (prefix == null) {
-            throw new IllegalArgumentException("Variable prefix must not be null.");
-        }
-        return setVariablePrefixMatcher(StrMatcher.stringMatcher(prefix));
+        return setVariablePrefixMatcher(StrMatcher.stringMatcher(Objects.requireNonNull(prefix)));
     }
 
     /**
@@ -1063,13 +1058,10 @@ public class StrSubstitutor {
      *
      * @param suffixMatcher  the suffix matcher to use, null ignored
      * @return this, to enable chaining
-     * @throws IllegalArgumentException if the suffix matcher is null
+     * @throws NullPointerException if the suffix matcher is null
      */
     public StrSubstitutor setVariableSuffixMatcher(final StrMatcher suffixMatcher) {
-        if (suffixMatcher == null) {
-            throw new IllegalArgumentException("Variable suffix matcher must not be null.");
-        }
-        this.suffixMatcher = suffixMatcher;
+        this.suffixMatcher = Objects.requireNonNull(suffixMatcher);
         return this;
     }
 
@@ -1097,13 +1089,10 @@ public class StrSubstitutor {
      *
      * @param suffix  the suffix for variables, not null
      * @return this, to enable chaining
-     * @throws IllegalArgumentException if the suffix is null
+     * @throws NullPointerException if the suffix is null
      */
     public StrSubstitutor setVariableSuffix(final String suffix) {
-       if (suffix == null) {
-            throw new IllegalArgumentException("Variable suffix must not be null.");
-        }
-        return setVariableSuffixMatcher(StrMatcher.stringMatcher(suffix));
+        return setVariableSuffixMatcher(StrMatcher.stringMatcher(Objects.requireNonNull(suffix)));
     }
 
     /**
diff --git a/src/main/java/org/apache/commons/lang3/time/DateUtils.java b/src/main/java/org/apache/commons/lang3/time/DateUtils.java
index 6710511b8..a45800c98 100644
--- a/src/main/java/org/apache/commons/lang3/time/DateUtils.java
+++ b/src/main/java/org/apache/commons/lang3/time/DateUtils.java
@@ -23,6 +23,7 @@ import java.util.Date;
 import java.util.Iterator;
 import java.util.Locale;
 import java.util.NoSuchElementException;
+import java.util.Objects;
 import java.util.TimeZone;
 import java.util.concurrent.TimeUnit;
 
@@ -159,13 +160,12 @@ public class DateUtils {
      * @param date1  the first date, not altered, not null
      * @param date2  the second date, not altered, not null
      * @return true if they represent the same day
-     * @throws IllegalArgumentException if either date is {@code null}
+     * @throws NullPointerException if either date is {@code null}
      * @since 2.1
      */
     public static boolean isSameDay(final Date date1, final Date date2) {
-        if (date1 == null || date2 == null) {
-            throw nullDateIllegalArgumentException();
-        }
+        Objects.requireNonNull(date1, "date1");
+        Objects.requireNonNull(date2, "date2");
         final Calendar cal1 = Calendar.getInstance();
         cal1.setTime(date1);
         final Calendar cal2 = Calendar.getInstance();
@@ -183,13 +183,12 @@ public class DateUtils {
      * @param cal1  the first calendar, not altered, not null
      * @param cal2  the second calendar, not altered, not null
      * @return true if they represent the same day
-     * @throws IllegalArgumentException if either calendar is {@code null}
+     * @throws NullPointerException if either calendar is {@code null}
      * @since 2.1
      */
     public static boolean isSameDay(final Calendar cal1, final Calendar cal2) {
-        if (cal1 == null || cal2 == null) {
-            throw nullDateIllegalArgumentException();
-        }
+        Objects.requireNonNull(cal1, "cal1");
+        Objects.requireNonNull(cal2, "cal2");
         return cal1.get(Calendar.ERA) == cal2.get(Calendar.ERA) &&
                 cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) &&
                 cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR);
@@ -203,13 +202,12 @@ public class DateUtils {
      * @param date1  the first date, not altered, not null
      * @param date2  the second date, not altered, not null
      * @return true if they represent the same millisecond instant
-     * @throws IllegalArgumentException if either date is {@code null}
+     * @throws NullPointerException if either date is {@code null}
      * @since 2.1
      */
     public static boolean isSameInstant(final Date date1, final Date date2) {
-        if (date1 == null || date2 == null) {
-            throw nullDateIllegalArgumentException();
-        }
+        Objects.requireNonNull(date1, "date1");
+        Objects.requireNonNull(date2, "date2");
         return date1.getTime() == date2.getTime();
     }
 
@@ -221,13 +219,12 @@ public class DateUtils {
      * @param cal1  the first calendar, not altered, not null
      * @param cal2  the second calendar, not altered, not null
      * @return true if they represent the same millisecond instant
-     * @throws IllegalArgumentException if either date is {@code null}
+     * @throws NullPointerException if either date is {@code null}
      * @since 2.1
      */
     public static boolean isSameInstant(final Calendar cal1, final Calendar cal2) {
-        if (cal1 == null || cal2 == null) {
-            throw nullDateIllegalArgumentException();
-        }
+        Objects.requireNonNull(cal1, "cal1");
+        Objects.requireNonNull(cal2, "cal2");
         return cal1.getTime().getTime() == cal2.getTime().getTime();
     }
 
@@ -240,13 +237,12 @@ public class DateUtils {
      * @param cal1  the first calendar, not altered, not null
      * @param cal2  the second calendar, not altered, not null
      * @return true if they represent the same millisecond instant
-     * @throws IllegalArgumentException if either date is {@code null}
+     * @throws NullPointerException if either date is {@code null}
      * @since 2.1
      */
     public static boolean isSameLocalTime(final Calendar cal1, final Calendar cal2) {
-        if (cal1 == null || cal2 == null) {
-            throw nullDateIllegalArgumentException();
-        }
+        Objects.requireNonNull(cal1, "cal1");
+        Objects.requireNonNull(cal2, "cal2");
         return cal1.get(Calendar.MILLISECOND) == cal2.get(Calendar.MILLISECOND) &&
                 cal1.get(Calendar.SECOND) == cal2.get(Calendar.SECOND) &&
                 cal1.get(Calendar.MINUTE) == cal2.get(Calendar.MINUTE) &&
@@ -268,7 +264,7 @@ public class DateUtils {
      * @param str  the date to parse, not null
      * @param parsePatterns  the date format patterns to use, see SimpleDateFormat, not null
      * @return the parsed date
-     * @throws IllegalArgumentException if the date string or pattern array is null
+     * @throws NullPointerException if the date string or pattern array is null
      * @throws ParseException if none of the date patterns were suitable (or there were none)
      */
     public static Date parseDate(final String str, final String... parsePatterns) throws ParseException {
@@ -289,7 +285,7 @@ public class DateUtils {
      * the system locale is used (as per {@link #parseDate(String, String...)}).
      * @param parsePatterns  the date format patterns to use, see SimpleDateFormat, not null
      * @return the parsed date
-     * @throws IllegalArgumentException if the date string or pattern array is null
+     * @throws NullPointerException if the date string or pattern array is null
      * @throws ParseException if none of the date patterns were suitable (or there were none)
      * @since 3.2
      */
@@ -308,7 +304,7 @@ public class DateUtils {
      * @param str  the date to parse, not null
      * @param parsePatterns  the date format patterns to use, see SimpleDateFormat, not null
      * @return the parsed date
-     * @throws IllegalArgumentException if the date string or pattern array is null
+     * @throws NullPointerException if the date string or pattern array is null
      * @throws ParseException if none of the date patterns were suitable
      * @since 2.5
      */
@@ -330,7 +326,7 @@ public class DateUtils {
      * the system locale is used (as per {@link #parseDateStrictly(String, String...)}).
      * @param parsePatterns  the date format patterns to use, see SimpleDateFormat, not null
      * @return the parsed date
-     * @throws IllegalArgumentException if the date string or pattern array is null
+     * @throws NullPointerException if the date string or pattern array is null
      * @throws ParseException if none of the date patterns were suitable
      * @since 3.2
      */
@@ -345,21 +341,20 @@ public class DateUtils {
      * A parse is only deemed successful if it parses the whole of the input string.
      * If no parse patterns match, a ParseException is thrown.</p>
      *
-     * @param str  the date to parse, not null
+     * @param dateStr  the date to parse, not null
      * @param locale the locale to use when interpreting the pattern, can be null in which
      * case the default system locale is used
      * @param parsePatterns  the date format patterns to use, see SimpleDateFormat, not null
      * @param lenient Specify whether or not date/time parsing is to be lenient.
      * @return the parsed date
-     * @throws IllegalArgumentException if the date string or pattern array is null
+     * @throws NullPointerException if the date string or pattern array is null
      * @throws ParseException if none of the date patterns were suitable
      * @see java.util.Calendar#isLenient()
      */
-    private static Date parseDateWithLeniency(final String str, final Locale locale, final String[] parsePatterns,
+    private static Date parseDateWithLeniency(final String dateStr, final Locale locale, final String[] parsePatterns,
         final boolean lenient) throws ParseException {
-        if (str == null || parsePatterns == null) {
-            throw new IllegalArgumentException("Date and Patterns must not be null");
-        }
+        Objects.requireNonNull(dateStr, "str");
+        Objects.requireNonNull(parsePatterns, "parsePatterns");
 
         final TimeZone tz = TimeZone.getDefault();
         final Locale lcl = LocaleUtils.toLocale(locale);
@@ -371,7 +366,7 @@ public class DateUtils {
             final FastDateParser fdp = new FastDateParser(parsePattern, tz, lcl);
             calendar.clear();
             try {
-                if (fdp.parse(str, pos, calendar) && pos.getIndex() == str.length()) {
+                if (fdp.parse(dateStr, pos, calendar) && pos.getIndex() == dateStr.length()) {
                     return calendar.getTime();
                 }
             } catch (final IllegalArgumentException ignored) {
@@ -379,7 +374,7 @@ public class DateUtils {
             }
             pos.setIndex(0);
         }
-        throw new ParseException("Unable to parse the date: " + str, -1);
+        throw new ParseException("Unable to parse the date: " + dateStr, -1);
     }
 
     /**
@@ -720,25 +715,19 @@ public class DateUtils {
      * <li>March 30, 2003 02:40 rounds to March 30, 2003 04:00</li>
      * </ul>
      *
-     * @param date  the date to work with, not null
+     * @param calendar  the date to work with, not null
      * @param field  the field from {@link Calendar} or {@code SEMI_MONTH}
      * @return the different rounded date, not null
-     * @throws IllegalArgumentException if the date is {@code null}
+     * @throws NullPointerException if the date is {@code null}
      * @throws ArithmeticException if the year is over 280 million
      */
-    public static Calendar round(final Calendar date, final int field) {
-        if (date == null) {
-            throw nullDateIllegalArgumentException();
-        }
-        final Calendar rounded = (Calendar) date.clone();
+    public static Calendar round(final Calendar calendar, final int field) {
+        Objects.requireNonNull(calendar, "calendar");
+        final Calendar rounded = (Calendar) calendar.clone();
         modify(rounded, field, ModifyType.ROUND);
         return rounded;
     }
 
-    private static IllegalArgumentException nullDateIllegalArgumentException() {
-        return new IllegalArgumentException("The date must not be null");
-    }
-
     /**
      * <p>Rounds a date, leaving the field specified as the most
      * significant field.</p>
@@ -763,14 +752,12 @@ public class DateUtils {
      * @param date  the date to work with, either {@link Date} or {@link Calendar}, not null
      * @param field  the field from {@link Calendar} or {@code SEMI_MONTH}
      * @return the different rounded date, not null
-     * @throws IllegalArgumentException if the date is {@code null}
+     * @throws NullPointerException if the date is {@code null}
      * @throws ClassCastException if the object type is not a {@link Date} or {@link Calendar}
      * @throws ArithmeticException if the year is over 280 million
      */
     public static Date round(final Object date, final int field) {
-        if (date == null) {
-            throw nullDateIllegalArgumentException();
-        }
+        Objects.requireNonNull(date, "date");
         if (date instanceof Date) {
             return round((Date) date, field);
         }
@@ -815,13 +802,11 @@ public class DateUtils {
      * @param date  the date to work with, not null
      * @param field  the field from {@link Calendar} or {@code SEMI_MONTH}
      * @return the different truncated date, not null
-     * @throws IllegalArgumentException if the date is {@code null}
+     * @throws NullPointerException if the date is {@code null}
      * @throws ArithmeticException if the year is over 280 million
      */
     public static Calendar truncate(final Calendar date, final int field) {
-        if (date == null) {
-            throw nullDateIllegalArgumentException();
-        }
+        Objects.requireNonNull(date, "date");
         final Calendar truncated = (Calendar) date.clone();
         modify(truncated, field, ModifyType.TRUNCATE);
         return truncated;
@@ -839,14 +824,12 @@ public class DateUtils {
      * @param date  the date to work with, either {@link Date} or {@link Calendar}, not null
      * @param field  the field from {@link Calendar} or {@code SEMI_MONTH}
      * @return the different truncated date, not null
-     * @throws IllegalArgumentException if the date is {@code null}
+     * @throws NullPointerException if the date is {@code null}
      * @throws ClassCastException if the object type is not a {@link Date} or {@link Calendar}
      * @throws ArithmeticException if the year is over 280 million
      */
     public static Date truncate(final Object date, final int field) {
-        if (date == null) {
-            throw nullDateIllegalArgumentException();
-        }
+        Objects.requireNonNull(date, "date");
         if (date instanceof Date) {
             return truncate((Date) date, field);
         }
@@ -889,18 +872,16 @@ public class DateUtils {
      * 2002 14:00:00.000.  If this was passed with MONTH, it would
      * return 1 Apr 2002 0:00:00.000.</p>
      *
-     * @param date  the date to work with, not null
+     * @param calendar  the date to work with, not null
      * @param field  the field from {@link Calendar} or {@code SEMI_MONTH}
      * @return the different ceil date, not null
-     * @throws IllegalArgumentException if the date is {@code null}
+     * @throws NullPointerException if the date is {@code null}
      * @throws ArithmeticException if the year is over 280 million
      * @since 2.5
      */
-    public static Calendar ceiling(final Calendar date, final int field) {
-        if (date == null) {
-            throw nullDateIllegalArgumentException();
-        }
-        final Calendar ceiled = (Calendar) date.clone();
+    public static Calendar ceiling(final Calendar calendar, final int field) {
+        Objects.requireNonNull(calendar, "calendar");
+        final Calendar ceiled = (Calendar) calendar.clone();
         modify(ceiled, field, ModifyType.CEILING);
         return ceiled;
     }
@@ -917,15 +898,13 @@ public class DateUtils {
      * @param date  the date to work with, either {@link Date} or {@link Calendar}, not null
      * @param field  the field from {@link Calendar} or {@code SEMI_MONTH}
      * @return the different ceil date, not null
-     * @throws IllegalArgumentException if the date is {@code null}
+     * @throws NullPointerException if the date is {@code null}
      * @throws ClassCastException if the object type is not a {@link Date} or {@link Calendar}
      * @throws ArithmeticException if the year is over 280 million
      * @since 2.5
      */
     public static Date ceiling(final Object date, final int field) {
-        if (date == null) {
-            throw nullDateIllegalArgumentException();
-        }
+        Objects.requireNonNull(date, "date");
         if (date instanceof Date) {
             return ceiling((Date) date, field);
         }
@@ -1126,7 +1105,7 @@ public class DateUtils {
      * <p>This method provides an iterator that returns Calendar objects.
      * The days are progressed using {@link Calendar#add(int, int)}.</p>
      *
-     * @param focus  the date to work with, not null
+     * @param calendar  the date to work with, not null
      * @param rangeStyle  the style constant to use. Must be one of
      * {@link DateUtils#RANGE_MONTH_SUNDAY},
      * {@link DateUtils#RANGE_MONTH_MONDAY},
@@ -1135,13 +1114,11 @@ public class DateUtils {
      * {@link DateUtils#RANGE_WEEK_RELATIVE},
      * {@link DateUtils#RANGE_WEEK_CENTER}
      * @return the date iterator, not null
-     * @throws IllegalArgumentException if calendar is {@code null}
+     * @throws NullPointerException if calendar is {@code null}
      * @throws IllegalArgumentException if the rangeStyle is invalid
      */
-    public static Iterator<Calendar> iterator(final Calendar focus, final int rangeStyle) {
-        if (focus == null) {
-            throw nullDateIllegalArgumentException();
-        }
+    public static Iterator<Calendar> iterator(final Calendar calendar, final int rangeStyle) {
+        Objects.requireNonNull(calendar, "calendar");
         final Calendar start;
         final Calendar end;
         int startCutoff = Calendar.SUNDAY;
@@ -1150,7 +1127,7 @@ public class DateUtils {
             case RANGE_MONTH_SUNDAY:
             case RANGE_MONTH_MONDAY:
                 //Set start to the first of the month
-                start = truncate(focus, Calendar.MONTH);
+                start = truncate(calendar, Calendar.MONTH);
                 //Set end to the last of the month
                 end = (Calendar) start.clone();
                 end.add(Calendar.MONTH, 1);
@@ -1166,8 +1143,8 @@ public class DateUtils {
             case RANGE_WEEK_RELATIVE:
             case RANGE_WEEK_CENTER:
                 //Set start and end to the current date
-                start = truncate(focus, Calendar.DATE);
-                end = truncate(focus, Calendar.DATE);
+                start = truncate(calendar, Calendar.DATE);
+                end = truncate(calendar, Calendar.DATE);
                 switch (rangeStyle) {
                     case RANGE_WEEK_SUNDAY:
                         //already set by default
@@ -1177,12 +1154,12 @@ public class DateUtils {
                         endCutoff = Calendar.SUNDAY;
                         break;
                     case RANGE_WEEK_RELATIVE:
-                        startCutoff = focus.get(Calendar.DAY_OF_WEEK);
+                        startCutoff = calendar.get(Calendar.DAY_OF_WEEK);
                         endCutoff = startCutoff - 1;
                         break;
                     case RANGE_WEEK_CENTER:
-                        startCutoff = focus.get(Calendar.DAY_OF_WEEK) - 3;
-                        endCutoff = focus.get(Calendar.DAY_OF_WEEK) + 3;
+                        startCutoff = calendar.get(Calendar.DAY_OF_WEEK) - 3;
+                        endCutoff = calendar.get(Calendar.DAY_OF_WEEK) + 3;
                         break;
                     default:
                         break;
@@ -1221,24 +1198,22 @@ public class DateUtils {
      * that starts with Sunday, June 30, 2002 and ends with Saturday, August 3,
      * 2002, returning a Calendar instance for each intermediate day.</p>
      *
-     * @param focus  the date to work with, either {@link Date} or {@link Calendar}, not null
+     * @param calendar  the date to work with, either {@link Date} or {@link Calendar}, not null
      * @param rangeStyle  the style constant to use. Must be one of the range
      * styles listed for the {@link #iterator(Calendar, int)} method.
      * @return the date iterator, not null
-     * @throws IllegalArgumentException if the date is {@code null}
+     * @throws NullPointerException if the date is {@code null}
      * @throws ClassCastException if the object type is not a {@link Date} or {@link Calendar}
      */
-    public static Iterator<?> iterator(final Object focus, final int rangeStyle) {
-        if (focus == null) {
-            throw nullDateIllegalArgumentException();
+    public static Iterator<?> iterator(final Object calendar, final int rangeStyle) {
+        Objects.requireNonNull(calendar, "calendar");
+        if (calendar instanceof Date) {
+            return iterator((Date) calendar, rangeStyle);
         }
-        if (focus instanceof Date) {
-            return iterator((Date) focus, rangeStyle);
+        if (calendar instanceof Calendar) {
+            return iterator((Calendar) calendar, rangeStyle);
         }
-        if (focus instanceof Calendar) {
-            return iterator((Calendar) focus, rangeStyle);
-        }
-        throw new ClassCastException("Could not iterate based on " + focus);
+        throw new ClassCastException("Could not iterate based on " + calendar);
     }
 
     /**
@@ -1458,7 +1433,7 @@ public class DateUtils {
      * @param calendar the calendar to work with, not null
      * @param fragment the {@link Calendar} field part of calendar to calculate
      * @return number of milliseconds within the fragment of date
-     * @throws IllegalArgumentException if the date is {@code null} or
+     * @throws NullPointerException if the date is {@code null} or
      * fragment is not supported
      * @since 2.4
      */
@@ -1495,7 +1470,7 @@ public class DateUtils {
      * @param calendar the calendar to work with, not null
      * @param fragment the {@link Calendar} field part of calendar to calculate
      * @return number of seconds within the fragment of date
-     * @throws IllegalArgumentException if the date is {@code null} or
+     * @throws NullPointerException if the date is {@code null} or
      * fragment is not supported
      * @since 2.4
      */
@@ -1533,7 +1508,7 @@ public class DateUtils {
      * @param calendar the calendar to work with, not null
      * @param fragment the {@link Calendar} field part of calendar to calculate
      * @return number of minutes within the fragment of date
-     * @throws IllegalArgumentException if the date is {@code null} or
+     * @throws NullPointerException if the date is {@code null} or
      * fragment is not supported
      * @since 2.4
      */
@@ -1571,7 +1546,7 @@ public class DateUtils {
      * @param calendar the calendar to work with, not null
      * @param fragment the {@link Calendar} field part of calendar to calculate
      * @return number of hours within the fragment of date
-     * @throws IllegalArgumentException if the date is {@code null} or
+     * @throws NullPointerException if the date is {@code null} or
      * fragment is not supported
      * @since 2.4
      */
@@ -1611,7 +1586,7 @@ public class DateUtils {
      * @param calendar the calendar to work with, not null
      * @param fragment the {@link Calendar} field part of calendar to calculate
      * @return number of days within the fragment of date
-     * @throws IllegalArgumentException if the date is {@code null} or
+     * @throws NullPointerException if the date is {@code null} or
      * fragment is not supported
      * @since 2.4
      */
@@ -1644,17 +1619,13 @@ public class DateUtils {
      * @param fragment the Calendar field part of calendar to calculate
      * @param unit the time unit
      * @return number of units within the fragment of the calendar
-     * @throws IllegalArgumentException if the date is {@code null} or
+     * @throws NullPointerException if the date is {@code null} or
      * fragment is not supported
      * @since 2.4
      */
     private static long getFragment(final Calendar calendar, final int fragment, final TimeUnit unit) {
-        if (calendar == null) {
-            throw  nullDateIllegalArgumentException();
-        }
-
+        Objects.requireNonNull(calendar, "calendar");
         long result = 0;
-
         final int offset = (unit == TimeUnit.DAYS) ? 0 : 1;
 
         // Fragments bigger than a day require a breakdown to days
@@ -1702,7 +1673,7 @@ public class DateUtils {
      * @param cal2 the second calendar, not {@code null}
      * @param field the field from {@link Calendar}
      * @return {@code true} if equal; otherwise {@code false}
-     * @throws IllegalArgumentException if any argument is {@code null}
+     * @throws NullPointerException if any argument is {@code null}
      * @see #truncate(Calendar, int)
      * @see #truncatedEquals(Date, Date, int)
      * @since 3.0
@@ -1737,7 +1708,7 @@ public class DateUtils {
      * @param field the field from {@link Calendar}
      * @return a negative integer, zero, or a positive integer as the first
      * calendar is less than, equal to, or greater than the second.
-     * @throws IllegalArgumentException if any argument is {@code null}
+     * @throws NullPointerException if any argument is {@code null}
      * @see #truncate(Calendar, int)
      * @see #truncatedCompareTo(Date, Date, int)
      * @since 3.0
diff --git a/src/test/java/org/apache/commons/lang3/text/StrSubstitutorTest.java b/src/test/java/org/apache/commons/lang3/text/StrSubstitutorTest.java
index 0321e738f..59ecfb504 100644
--- a/src/test/java/org/apache/commons/lang3/text/StrSubstitutorTest.java
+++ b/src/test/java/org/apache/commons/lang3/text/StrSubstitutorTest.java
@@ -469,13 +469,13 @@ public class StrSubstitutorTest {
 
         sub.setVariablePrefix("<<");
         assertTrue(sub.getVariablePrefixMatcher() instanceof StrMatcher.StringMatcher);
-        assertThrows(IllegalArgumentException.class, () -> sub.setVariablePrefix(null));
+        assertThrows(NullPointerException.class, () -> sub.setVariablePrefix(null));
         assertTrue(sub.getVariablePrefixMatcher() instanceof StrMatcher.StringMatcher);
 
         final StrMatcher matcher = StrMatcher.commaMatcher();
         sub.setVariablePrefixMatcher(matcher);
         assertSame(matcher, sub.getVariablePrefixMatcher());
-        assertThrows(IllegalArgumentException.class, () -> sub.setVariablePrefixMatcher(null));
+        assertThrows(NullPointerException.class, () -> sub.setVariablePrefixMatcher(null));
         assertSame(matcher, sub.getVariablePrefixMatcher());
     }
 
@@ -491,13 +491,13 @@ public class StrSubstitutorTest {
 
         sub.setVariableSuffix("<<");
         assertTrue(sub.getVariableSuffixMatcher() instanceof StrMatcher.StringMatcher);
-        assertThrows(IllegalArgumentException.class, () -> sub.setVariableSuffix(null));
+        assertThrows(NullPointerException.class, () -> sub.setVariableSuffix(null));
         assertTrue(sub.getVariableSuffixMatcher() instanceof StrMatcher.StringMatcher);
 
         final StrMatcher matcher = StrMatcher.commaMatcher();
         sub.setVariableSuffixMatcher(matcher);
         assertSame(matcher, sub.getVariableSuffixMatcher());
-        assertThrows(IllegalArgumentException.class, () -> sub.setVariableSuffixMatcher(null));
+        assertThrows(NullPointerException.class, () -> sub.setVariableSuffixMatcher(null));
         assertSame(matcher, sub.getVariableSuffixMatcher());
     }
 
diff --git a/src/test/java/org/apache/commons/lang3/time/DateUtilsFragmentTest.java b/src/test/java/org/apache/commons/lang3/time/DateUtilsFragmentTest.java
index 8e2913fde..984189773 100644
--- a/src/test/java/org/apache/commons/lang3/time/DateUtilsFragmentTest.java
+++ b/src/test/java/org/apache/commons/lang3/time/DateUtilsFragmentTest.java
@@ -388,48 +388,20 @@ testResult);
 
     @Test
     public void testNullCalendar() {
-        assertThrows(
-                IllegalArgumentException.class,
-                () -> DateUtils.getFragmentInMilliseconds((Calendar) null, Calendar.MILLISECOND));
-
-        assertThrows(
-                IllegalArgumentException.class,
-                () -> DateUtils.getFragmentInSeconds((Calendar) null, Calendar.MILLISECOND));
-
-        assertThrows(
-                IllegalArgumentException.class,
-                () -> DateUtils.getFragmentInMinutes((Calendar) null, Calendar.MILLISECOND));
-
-        assertThrows(
-                IllegalArgumentException.class,
-                () -> DateUtils.getFragmentInHours((Calendar) null, Calendar.MILLISECOND));
-
-        assertThrows(
-                IllegalArgumentException.class,
-                () -> DateUtils.getFragmentInDays((Calendar) null, Calendar.MILLISECOND));
+        assertThrows(NullPointerException.class, () -> DateUtils.getFragmentInMilliseconds((Calendar) null, Calendar.MILLISECOND));
+        assertThrows(NullPointerException.class, () -> DateUtils.getFragmentInSeconds((Calendar) null, Calendar.MILLISECOND));
+        assertThrows(NullPointerException.class, () -> DateUtils.getFragmentInMinutes((Calendar) null, Calendar.MILLISECOND));
+        assertThrows(NullPointerException.class, () -> DateUtils.getFragmentInHours((Calendar) null, Calendar.MILLISECOND));
+        assertThrows(NullPointerException.class, () -> DateUtils.getFragmentInDays((Calendar) null, Calendar.MILLISECOND));
     }
 
     @Test
     public void testNullDate() {
-        assertThrows(
-                NullPointerException.class,
-                () -> DateUtils.getFragmentInMilliseconds((Date) null, Calendar.MILLISECOND));
-
-        assertThrows(
-                NullPointerException.class,
-                () -> DateUtils.getFragmentInSeconds((Date) null, Calendar.MILLISECOND));
-
-        assertThrows(
-                NullPointerException.class,
-                () -> DateUtils.getFragmentInMinutes((Date) null, Calendar.MILLISECOND));
-
-        assertThrows(
-                NullPointerException.class,
-                () -> DateUtils.getFragmentInHours((Date) null, Calendar.MILLISECOND));
-
-        assertThrows(
-                NullPointerException.class,
-                () -> DateUtils.getFragmentInDays((Date) null, Calendar.MILLISECOND));
+        assertThrows(NullPointerException.class, () -> DateUtils.getFragmentInMilliseconds((Date) null, Calendar.MILLISECOND));
+        assertThrows(NullPointerException.class, () -> DateUtils.getFragmentInSeconds((Date) null, Calendar.MILLISECOND));
+        assertThrows(NullPointerException.class, () -> DateUtils.getFragmentInMinutes((Date) null, Calendar.MILLISECOND));
+        assertThrows(NullPointerException.class, () -> DateUtils.getFragmentInHours((Date) null, Calendar.MILLISECOND));
+        assertThrows(NullPointerException.class, () -> DateUtils.getFragmentInDays((Date) null, Calendar.MILLISECOND));
     }
 
     @Test
diff --git a/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java b/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java
index f57bf0006..5c84ab3e3 100644
--- a/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java
@@ -526,8 +526,8 @@ public class DateUtilsTest {
                 "ceiling ampm-4 failed");
 
         assertThrows(NullPointerException.class, () -> DateUtils.ceiling((Date) null, Calendar.SECOND));
-        assertThrows(IllegalArgumentException.class, () -> DateUtils.ceiling((Calendar) null, Calendar.SECOND));
-        assertThrows(IllegalArgumentException.class, () -> DateUtils.ceiling((Object) null, Calendar.SECOND));
+        assertThrows(NullPointerException.class, () -> DateUtils.ceiling((Calendar) null, Calendar.SECOND));
+        assertThrows(NullPointerException.class, () -> DateUtils.ceiling((Object) null, Calendar.SECOND));
         assertThrows(ClassCastException.class, () -> DateUtils.ceiling("", Calendar.SECOND));
         assertThrows(IllegalArgumentException.class, () -> DateUtils.ceiling(date1, -9999));
 
@@ -629,17 +629,17 @@ public class DateUtilsTest {
 
     @Test
     public void testIsSameDay_CalNotNullNull() {
-        assertThrows(IllegalArgumentException.class, () -> DateUtils.isSameDay(Calendar.getInstance(), null));
+        assertThrows(NullPointerException.class, () -> DateUtils.isSameDay(Calendar.getInstance(), null));
     }
 
     @Test
     public void testIsSameDay_CalNullNotNull() {
-        assertThrows(IllegalArgumentException.class, () -> DateUtils.isSameDay(null, Calendar.getInstance()));
+        assertThrows(NullPointerException.class, () -> DateUtils.isSameDay(null, Calendar.getInstance()));
     }
 
     @Test
     public void testIsSameDay_CalNullNull() {
-        assertThrows(IllegalArgumentException.class, () -> DateUtils.isSameDay((Calendar) null, null));
+        assertThrows(NullPointerException.class, () -> DateUtils.isSameDay((Calendar) null, null));
     }
 
     @Test
@@ -657,17 +657,17 @@ public class DateUtilsTest {
 
     @Test
     public void testIsSameDay_DateNotNullNull() {
-        assertThrows(IllegalArgumentException.class, () -> DateUtils.isSameDay(new Date(), null));
+        assertThrows(NullPointerException.class, () -> DateUtils.isSameDay(new Date(), null));
     }
 
     @Test
     public void testIsSameDay_DateNullNotNull() {
-        assertThrows(IllegalArgumentException.class, () -> DateUtils.isSameDay(null, new Date()));
+        assertThrows(NullPointerException.class, () -> DateUtils.isSameDay(null, new Date()));
     }
 
     @Test
     public void testIsSameDay_DateNullNull() {
-        assertThrows(IllegalArgumentException.class, () -> DateUtils.isSameDay((Date) null, null));
+        assertThrows(NullPointerException.class, () -> DateUtils.isSameDay((Date) null, null));
     }
 
     @Test
@@ -686,17 +686,17 @@ public class DateUtilsTest {
 
     @Test
     public void testIsSameInstant_CalNotNullNull() {
-        assertThrows(IllegalArgumentException.class, () -> DateUtils.isSameInstant(Calendar.getInstance(), null));
+        assertThrows(NullPointerException.class, () -> DateUtils.isSameInstant(Calendar.getInstance(), null));
     }
 
     @Test
     public void testIsSameInstant_CalNullNotNull() {
-        assertThrows(IllegalArgumentException.class, () -> DateUtils.isSameInstant(null, Calendar.getInstance()));
+        assertThrows(NullPointerException.class, () -> DateUtils.isSameInstant(null, Calendar.getInstance()));
     }
 
     @Test
     public void testIsSameInstant_CalNullNull() {
-        assertThrows(IllegalArgumentException.class, () -> DateUtils.isSameInstant((Calendar) null, null));
+        assertThrows(NullPointerException.class, () -> DateUtils.isSameInstant((Calendar) null, null));
     }
 
     @Test
@@ -714,17 +714,17 @@ public class DateUtilsTest {
 
     @Test
     public void testIsSameInstant_DateNotNullNull() {
-        assertThrows(IllegalArgumentException.class, () -> DateUtils.isSameInstant(new Date(), null));
+        assertThrows(NullPointerException.class, () -> DateUtils.isSameInstant(new Date(), null));
     }
 
     @Test
     public void testIsSameInstant_DateNullNotNull() {
-        assertThrows(IllegalArgumentException.class, () -> DateUtils.isSameInstant(null, new Date()));
+        assertThrows(NullPointerException.class, () -> DateUtils.isSameInstant(null, new Date()));
     }
 
     @Test
     public void testIsSameInstant_DateNullNull() {
-        assertThrows(IllegalArgumentException.class, () -> DateUtils.isSameInstant((Date) null, null));
+        assertThrows(NullPointerException.class, () -> DateUtils.isSameInstant((Date) null, null));
     }
 
     @Test
@@ -751,17 +751,17 @@ public class DateUtilsTest {
 
     @Test
     public void testIsSameLocalTime_CalNotNullNull() {
-        assertThrows(IllegalArgumentException.class, () -> DateUtils.isSameLocalTime(Calendar.getInstance(), null));
+        assertThrows(NullPointerException.class, () -> DateUtils.isSameLocalTime(Calendar.getInstance(), null));
     }
 
     @Test
     public void testIsSameLocalTime_CalNullNotNull() {
-        assertThrows(IllegalArgumentException.class, () -> DateUtils.isSameLocalTime(null, Calendar.getInstance()));
+        assertThrows(NullPointerException.class, () -> DateUtils.isSameLocalTime(null, Calendar.getInstance()));
     }
 
     @Test
     public void testIsSameLocalTime_CalNullNull() {
-        assertThrows(IllegalArgumentException.class, () -> DateUtils.isSameLocalTime(null, null));
+        assertThrows(NullPointerException.class, () -> DateUtils.isSameLocalTime(null, null));
     }
 
     /**
@@ -770,12 +770,9 @@ public class DateUtilsTest {
     @Test
     public void testIteratorEx() {
         assertThrows(IllegalArgumentException.class, () -> DateUtils.iterator(Calendar.getInstance(), -9999));
-        assertThrows
-                (NullPointerException.class, () -> DateUtils.iterator((Date) null, DateUtils.RANGE_WEEK_CENTER));
-        assertThrows
-                (IllegalArgumentException.class, () -> DateUtils.iterator((Calendar) null, DateUtils.RANGE_WEEK_CENTER));
-        assertThrows
-                (IllegalArgumentException.class, () -> DateUtils.iterator((Object) null, DateUtils.RANGE_WEEK_CENTER));
+        assertThrows(NullPointerException.class, () -> DateUtils.iterator((Date) null, DateUtils.RANGE_WEEK_CENTER));
+        assertThrows(NullPointerException.class, () -> DateUtils.iterator((Calendar) null, DateUtils.RANGE_WEEK_CENTER));
+        assertThrows(NullPointerException.class, () -> DateUtils.iterator((Object) null, DateUtils.RANGE_WEEK_CENTER));
         assertThrows(ClassCastException.class, () -> DateUtils.iterator("", DateUtils.RANGE_WEEK_CENTER));
     }
 
@@ -865,7 +862,7 @@ public class DateUtilsTest {
 
     @Test
     public void testParse_NullParsers() {
-        assertThrows(IllegalArgumentException.class, () -> DateUtils.parseDate("19721203", (String[]) null));
+        assertThrows(NullPointerException.class, () -> DateUtils.parseDate("19721203", (String[]) null));
     }
 
     @Test
@@ -900,7 +897,7 @@ public class DateUtilsTest {
     @Test
     public void testParseDate_Null() {
         final String[] parsers = {"yyyy'-'DDD", "yyyy'-'MM'-'dd", "yyyyMMdd"};
-        assertThrows(IllegalArgumentException.class, () -> DateUtils.parseDate(null, parsers));
+        assertThrows(NullPointerException.class, () -> DateUtils.parseDate(null, parsers));
     }
 
     // LANG-486
@@ -1047,8 +1044,8 @@ public class DateUtilsTest {
                 "round ampm-4 failed");
 
         assertThrows(NullPointerException.class, () -> DateUtils.round((Date) null, Calendar.SECOND));
-        assertThrows(IllegalArgumentException.class, () -> DateUtils.round((Calendar) null, Calendar.SECOND));
-        assertThrows(IllegalArgumentException.class, () -> DateUtils.round((Object) null, Calendar.SECOND));
+        assertThrows(NullPointerException.class, () -> DateUtils.round((Calendar) null, Calendar.SECOND));
+        assertThrows(NullPointerException.class, () -> DateUtils.round((Object) null, Calendar.SECOND));
         assertThrows(ClassCastException.class, () -> DateUtils.round("", Calendar.SECOND));
         assertThrows(IllegalArgumentException.class, () -> DateUtils.round(date1, -9999));
 
@@ -1531,8 +1528,8 @@ public class DateUtilsTest {
                 "truncate ampm-4 failed");
 
         assertThrows(NullPointerException.class, () -> DateUtils.truncate((Date) null, Calendar.SECOND));
-        assertThrows(IllegalArgumentException.class, () -> DateUtils.truncate((Calendar) null, Calendar.SECOND));
-        assertThrows(IllegalArgumentException.class, () -> DateUtils.truncate((Object) null, Calendar.SECOND));
+        assertThrows(NullPointerException.class, () -> DateUtils.truncate((Calendar) null, Calendar.SECOND));
+        assertThrows(NullPointerException.class, () -> DateUtils.truncate((Object) null, Calendar.SECOND));
         assertThrows(ClassCastException.class, () -> DateUtils.truncate("", Calendar.SECOND));
 
         // Fix for https://issues.apache.org/bugzilla/show_bug.cgi?id=25560


[commons-lang] 09/09: Add SystemUtils.IS_JAVA_17

Posted by gg...@apache.org.
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-lang.git

commit 6001ae8a0c9f5815ee368ae1967d6de1b786a9e7
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Jul 5 10:25:46 2022 -0400

    Add SystemUtils.IS_JAVA_17
---
 src/changes/changes.xml                            |  1 +
 .../java/org/apache/commons/lang3/SystemUtils.java | 10 ++++++++
 .../org/apache/commons/lang3/SystemUtilsTest.java  | 29 ++++++++++++++++++++++
 3 files changed, 40 insertions(+)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 8e8a16353..1b7ca9fe7 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -152,6 +152,7 @@ The <action> type attribute can be add,update,fix,remove.
     <action                   type="add" dev="ggregory" due-to="Gary Gregory">Add ExceptionUtils.stream(Throwable).</action>
     <action                   type="add" dev="ggregory" due-to="Gary Gregory">Add ExceptionUtils.getRootCauseStackTraceList(Throwable).</action>
     <action                   type="add" dev="ggregory" due-to="Will Herrmann, Gary Gregory, Roland Kreuzer">Add SystemUtils.IS_OS_WINDOWS_11.</action>
+    <action                   type="add" dev="ggregory" due-to="Gary Gregory">Add SystemUtils.IS_JAVA_17.</action>
     <!-- UPDATE -->
     <action                   type="update" dev="ggregory" due-to="Dependabot, XenoAmess, Gary Gregory">Bump actions/cache from 2.1.4 to 3.0.4 #742, #752, #764, #833, #867.</action>
     <action                   type="update" dev="ggregory" due-to="Dependabot">Bump actions/checkout from 2 to 3 #819, #825, #859.</action>
diff --git a/src/main/java/org/apache/commons/lang3/SystemUtils.java b/src/main/java/org/apache/commons/lang3/SystemUtils.java
index 4a810cdc0..12db15573 100644
--- a/src/main/java/org/apache/commons/lang3/SystemUtils.java
+++ b/src/main/java/org/apache/commons/lang3/SystemUtils.java
@@ -1060,6 +1060,16 @@ public class SystemUtils {
      */
     public static final boolean IS_JAVA_16 = getJavaVersionMatches("16");
 
+    /**
+     * Is {@code true} if this is Java version 17 (also 17.x versions).
+     * <p>
+     * The field will return {@code false} if {@link #JAVA_VERSION} is {@code null}.
+     * </p>
+     *
+     * @since 3.13.0
+     */
+    public static final boolean IS_JAVA_17 = getJavaVersionMatches("17");
+
     // Operating system checks
     // -----------------------------------------------------------------------
     // These MUST be declared after those above as they depend on the
diff --git a/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java b/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java
index 3c4ca25b9..61237a232 100644
--- a/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java
@@ -74,6 +74,7 @@ public class SystemUtilsTest {
             assertFalse(SystemUtils.IS_JAVA_14);
             assertFalse(SystemUtils.IS_JAVA_15);
             assertFalse(SystemUtils.IS_JAVA_16);
+            assertFalse(SystemUtils.IS_JAVA_17);
         } else if (javaVersion.startsWith("1.8")) {
             assertFalse(SystemUtils.IS_JAVA_1_1);
             assertFalse(SystemUtils.IS_JAVA_1_2);
@@ -92,6 +93,7 @@ public class SystemUtilsTest {
             assertFalse(SystemUtils.IS_JAVA_14);
             assertFalse(SystemUtils.IS_JAVA_15);
             assertFalse(SystemUtils.IS_JAVA_16);
+            assertFalse(SystemUtils.IS_JAVA_17);
         } else if (javaVersion.startsWith("9")) {
             assertFalse(SystemUtils.IS_JAVA_1_1);
             assertFalse(SystemUtils.IS_JAVA_1_2);
@@ -110,6 +112,7 @@ public class SystemUtilsTest {
             assertFalse(SystemUtils.IS_JAVA_14);
             assertFalse(SystemUtils.IS_JAVA_15);
             assertFalse(SystemUtils.IS_JAVA_16);
+            assertFalse(SystemUtils.IS_JAVA_17);
         } else if (javaVersion.startsWith("10")) {
             assertFalse(SystemUtils.IS_JAVA_1_1);
             assertFalse(SystemUtils.IS_JAVA_1_2);
@@ -128,6 +131,7 @@ public class SystemUtilsTest {
             assertFalse(SystemUtils.IS_JAVA_14);
             assertFalse(SystemUtils.IS_JAVA_15);
             assertFalse(SystemUtils.IS_JAVA_16);
+            assertFalse(SystemUtils.IS_JAVA_17);
         } else if (javaVersion.startsWith("11")) {
             assertFalse(SystemUtils.IS_JAVA_1_1);
             assertFalse(SystemUtils.IS_JAVA_1_2);
@@ -146,6 +150,7 @@ public class SystemUtilsTest {
             assertFalse(SystemUtils.IS_JAVA_14);
             assertFalse(SystemUtils.IS_JAVA_15);
             assertFalse(SystemUtils.IS_JAVA_16);
+            assertFalse(SystemUtils.IS_JAVA_17);
         } else if (javaVersion.startsWith("12")) {
             assertFalse(SystemUtils.IS_JAVA_1_1);
             assertFalse(SystemUtils.IS_JAVA_1_2);
@@ -164,6 +169,7 @@ public class SystemUtilsTest {
             assertFalse(SystemUtils.IS_JAVA_14);
             assertFalse(SystemUtils.IS_JAVA_15);
             assertFalse(SystemUtils.IS_JAVA_16);
+            assertFalse(SystemUtils.IS_JAVA_17);
         } else if (javaVersion.startsWith("13")) {
             assertFalse(SystemUtils.IS_JAVA_1_1);
             assertFalse(SystemUtils.IS_JAVA_1_2);
@@ -182,6 +188,7 @@ public class SystemUtilsTest {
             assertFalse(SystemUtils.IS_JAVA_14);
             assertFalse(SystemUtils.IS_JAVA_15);
             assertFalse(SystemUtils.IS_JAVA_16);
+            assertFalse(SystemUtils.IS_JAVA_17);
         } else if (javaVersion.startsWith("14")) {
             assertFalse(SystemUtils.IS_JAVA_1_1);
             assertFalse(SystemUtils.IS_JAVA_1_2);
@@ -200,6 +207,7 @@ public class SystemUtilsTest {
             assertTrue(SystemUtils.IS_JAVA_14);
             assertFalse(SystemUtils.IS_JAVA_15);
             assertFalse(SystemUtils.IS_JAVA_16);
+            assertFalse(SystemUtils.IS_JAVA_17);
         } else if (javaVersion.startsWith("15")) {
             assertFalse(SystemUtils.IS_JAVA_1_1);
             assertFalse(SystemUtils.IS_JAVA_1_2);
@@ -218,6 +226,7 @@ public class SystemUtilsTest {
             assertFalse(SystemUtils.IS_JAVA_14);
             assertTrue(SystemUtils.IS_JAVA_15);
             assertFalse(SystemUtils.IS_JAVA_16);
+            assertFalse(SystemUtils.IS_JAVA_17);
         } else if (javaVersion.startsWith("16")) {
             assertFalse(SystemUtils.IS_JAVA_1_1);
             assertFalse(SystemUtils.IS_JAVA_1_2);
@@ -236,6 +245,26 @@ public class SystemUtilsTest {
             assertFalse(SystemUtils.IS_JAVA_14);
             assertFalse(SystemUtils.IS_JAVA_15);
             assertTrue(SystemUtils.IS_JAVA_16);
+            assertFalse(SystemUtils.IS_JAVA_17);
+        } else if (javaVersion.startsWith("17")) {
+            assertFalse(SystemUtils.IS_JAVA_1_1);
+            assertFalse(SystemUtils.IS_JAVA_1_2);
+            assertFalse(SystemUtils.IS_JAVA_1_3);
+            assertFalse(SystemUtils.IS_JAVA_1_4);
+            assertFalse(SystemUtils.IS_JAVA_1_5);
+            assertFalse(SystemUtils.IS_JAVA_1_6);
+            assertFalse(SystemUtils.IS_JAVA_1_7);
+            assertFalse(SystemUtils.IS_JAVA_1_8);
+            assertFalse(SystemUtils.IS_JAVA_1_9);
+            assertFalse(SystemUtils.IS_JAVA_9);
+            assertFalse(SystemUtils.IS_JAVA_10);
+            assertFalse(SystemUtils.IS_JAVA_11);
+            assertFalse(SystemUtils.IS_JAVA_12);
+            assertFalse(SystemUtils.IS_JAVA_13);
+            assertFalse(SystemUtils.IS_JAVA_14);
+            assertFalse(SystemUtils.IS_JAVA_15);
+            assertFalse(SystemUtils.IS_JAVA_16);
+            assertTrue(SystemUtils.IS_JAVA_17);
         } else {
             System.out.println("Can't test IS_JAVA value: " + javaVersion);
         }


[commons-lang] 04/09: Internal refactoring around private modify() method

Posted by gg...@apache.org.
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-lang.git

commit 5cd20a04a0d2fbd8f281196fbc797e8eec6cd6e0
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Jul 5 09:49:33 2022 -0400

    Internal refactoring around private modify() method
---
 .../org/apache/commons/lang3/time/DateUtils.java   | 29 ++++++++--------------
 1 file changed, 10 insertions(+), 19 deletions(-)

diff --git a/src/main/java/org/apache/commons/lang3/time/DateUtils.java b/src/main/java/org/apache/commons/lang3/time/DateUtils.java
index a45800c98..c0e0e92c7 100644
--- a/src/main/java/org/apache/commons/lang3/time/DateUtils.java
+++ b/src/main/java/org/apache/commons/lang3/time/DateUtils.java
@@ -690,8 +690,7 @@ public class DateUtils {
         validateDateNotNull(date);
         final Calendar gval = Calendar.getInstance();
         gval.setTime(date);
-        modify(gval, field, ModifyType.ROUND);
-        return gval.getTime();
+        return modify(gval, field, ModifyType.ROUND).getTime();
     }
 
     /**
@@ -723,9 +722,7 @@ public class DateUtils {
      */
     public static Calendar round(final Calendar calendar, final int field) {
         Objects.requireNonNull(calendar, "calendar");
-        final Calendar rounded = (Calendar) calendar.clone();
-        modify(rounded, field, ModifyType.ROUND);
-        return rounded;
+        return modify((Calendar) calendar.clone(), field, ModifyType.ROUND);
     }
 
     /**
@@ -786,8 +783,7 @@ public class DateUtils {
         validateDateNotNull(date);
         final Calendar gval = Calendar.getInstance();
         gval.setTime(date);
-        modify(gval, field, ModifyType.TRUNCATE);
-        return gval.getTime();
+        return modify(gval, field, ModifyType.TRUNCATE).getTime();
     }
 
     /**
@@ -807,9 +803,7 @@ public class DateUtils {
      */
     public static Calendar truncate(final Calendar date, final int field) {
         Objects.requireNonNull(date, "date");
-        final Calendar truncated = (Calendar) date.clone();
-        modify(truncated, field, ModifyType.TRUNCATE);
-        return truncated;
+        return modify((Calendar) date.clone(), field, ModifyType.TRUNCATE);
     }
 
     /**
@@ -859,8 +853,7 @@ public class DateUtils {
         validateDateNotNull(date);
         final Calendar gval = Calendar.getInstance();
         gval.setTime(date);
-        modify(gval, field, ModifyType.CEILING);
-        return gval.getTime();
+        return modify(gval, field, ModifyType.CEILING).getTime();
     }
 
     /**
@@ -881,9 +874,7 @@ public class DateUtils {
      */
     public static Calendar ceiling(final Calendar calendar, final int field) {
         Objects.requireNonNull(calendar, "calendar");
-        final Calendar ceiled = (Calendar) calendar.clone();
-        modify(ceiled, field, ModifyType.CEILING);
-        return ceiled;
+        return modify((Calendar) calendar.clone(), field, ModifyType.CEILING);
     }
 
     /**
@@ -920,15 +911,16 @@ public class DateUtils {
      * @param val  the calendar, not null
      * @param field  the field constant
      * @param modType  type to truncate, round or ceiling
+     * @return the given calendar
      * @throws ArithmeticException if the year is over 280 million
      */
-    private static void modify(final Calendar val, final int field, final ModifyType modType) {
+    private static Calendar modify(final Calendar val, final int field, final ModifyType modType) {
         if (val.get(Calendar.YEAR) > 280000000) {
             throw new ArithmeticException("Calendar value too large for accurate calculations");
         }
 
         if (field == Calendar.MILLISECOND) {
-            return;
+            return val;
         }
 
         // ----------------- Fix for LANG-59 ---------------------- START ---------------
@@ -1006,7 +998,7 @@ public class DateUtils {
                             val.add(aField[0], 1);
                         }
                     }
-                    return;
+                    return val;
                 }
             }
             //We have various fields that are not easy roundings
@@ -1059,7 +1051,6 @@ public class DateUtils {
             }
         }
         throw new IllegalArgumentException("The field " + field + " is not supported");
-
     }
 
     /**


[commons-lang] 05/09: Reuse our DateUtils#toCalendar(Date) API

Posted by gg...@apache.org.
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-lang.git

commit 2073de1450e7f6c9826f92882373ccf86859979f
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Jul 5 10:07:33 2022 -0400

    Reuse our DateUtils#toCalendar(Date) API
---
 .../org/apache/commons/lang3/time/DateUtils.java   | 32 +++++-----------------
 1 file changed, 7 insertions(+), 25 deletions(-)

diff --git a/src/main/java/org/apache/commons/lang3/time/DateUtils.java b/src/main/java/org/apache/commons/lang3/time/DateUtils.java
index c0e0e92c7..b6db859c3 100644
--- a/src/main/java/org/apache/commons/lang3/time/DateUtils.java
+++ b/src/main/java/org/apache/commons/lang3/time/DateUtils.java
@@ -164,13 +164,7 @@ public class DateUtils {
      * @since 2.1
      */
     public static boolean isSameDay(final Date date1, final Date date2) {
-        Objects.requireNonNull(date1, "date1");
-        Objects.requireNonNull(date2, "date2");
-        final Calendar cal1 = Calendar.getInstance();
-        cal1.setTime(date1);
-        final Calendar cal2 = Calendar.getInstance();
-        cal2.setTime(date2);
-        return isSameDay(cal1, cal2);
+        return isSameDay(toCalendar(date1), toCalendar(date2));
     }
 
     /**
@@ -642,7 +636,7 @@ public class DateUtils {
      */
     public static Calendar toCalendar(final Date date) {
         final Calendar c = Calendar.getInstance();
-        c.setTime(date);
+        c.setTime(Objects.requireNonNull(date, "date"));
         return c;
     }
 
@@ -655,7 +649,7 @@ public class DateUtils {
      */
     public static Calendar toCalendar(final Date date, final TimeZone tz) {
         final Calendar c = Calendar.getInstance(tz);
-        c.setTime(date);
+        c.setTime(Objects.requireNonNull(date, "date"));
         return c;
     }
 
@@ -687,10 +681,7 @@ public class DateUtils {
      * @throws ArithmeticException if the year is over 280 million
      */
     public static Date round(final Date date, final int field) {
-        validateDateNotNull(date);
-        final Calendar gval = Calendar.getInstance();
-        gval.setTime(date);
-        return modify(gval, field, ModifyType.ROUND).getTime();
+        return modify(toCalendar(date), field, ModifyType.ROUND).getTime();
     }
 
     /**
@@ -780,10 +771,7 @@ public class DateUtils {
      * @throws ArithmeticException if the year is over 280 million
      */
     public static Date truncate(final Date date, final int field) {
-        validateDateNotNull(date);
-        final Calendar gval = Calendar.getInstance();
-        gval.setTime(date);
-        return modify(gval, field, ModifyType.TRUNCATE).getTime();
+        return modify(toCalendar(date), field, ModifyType.TRUNCATE).getTime();
     }
 
     /**
@@ -850,10 +838,7 @@ public class DateUtils {
      * @since 2.5
      */
     public static Date ceiling(final Date date, final int field) {
-        validateDateNotNull(date);
-        final Calendar gval = Calendar.getInstance();
-        gval.setTime(date);
-        return modify(gval, field, ModifyType.CEILING).getTime();
+        return modify(toCalendar(date), field, ModifyType.CEILING).getTime();
     }
 
     /**
@@ -1078,10 +1063,7 @@ public class DateUtils {
      * @throws IllegalArgumentException if the rangeStyle is invalid
      */
     public static Iterator<Calendar> iterator(final Date focus, final int rangeStyle) {
-        validateDateNotNull(focus);
-        final Calendar gval = Calendar.getInstance();
-        gval.setTime(focus);
-        return iterator(gval, rangeStyle);
+        return iterator(toCalendar(focus), rangeStyle);
     }
 
     /**


[commons-lang] 08/09: Clean up inline comments

Posted by gg...@apache.org.
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-lang.git

commit edbaebb4d1e5b59da69a451eed5acb326c47879e
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Jul 5 10:16:48 2022 -0400

    Clean up inline comments
---
 src/main/java/org/apache/commons/lang3/time/DateUtils.java | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/apache/commons/lang3/time/DateUtils.java b/src/main/java/org/apache/commons/lang3/time/DateUtils.java
index b6db859c3..aadfdbb31 100644
--- a/src/main/java/org/apache/commons/lang3/time/DateUtils.java
+++ b/src/main/java/org/apache/commons/lang3/time/DateUtils.java
@@ -908,7 +908,7 @@ public class DateUtils {
             return val;
         }
 
-        // ----------------- Fix for LANG-59 ---------------------- START ---------------
+        // Fix for LANG-59 START
         // see https://issues.apache.org/jira/browse/LANG-59
         //
         // Manually truncate milliseconds, seconds and minutes, rather than using
@@ -947,7 +947,7 @@ public class DateUtils {
             date.setTime(time);
             val.setTime(date);
         }
-        // ----------------- Fix for LANG-59 ----------------------- END ----------------
+        // Fix for LANG-59 END
 
         boolean roundUp = false;
         for (final int[] aField : fields) {
@@ -965,7 +965,7 @@ public class DateUtils {
                                 val.add(Calendar.DATE, -15);
                                 val.add(Calendar.MONTH, 1);
                             }
-// ----------------- Fix for LANG-440 ---------------------- START ---------------
+                        // Fix for LANG-440 START
                         } else if (field == Calendar.AM_PM) {
                             // This is a special case
                             // If the time is 0, we round up to 12, otherwise
@@ -976,7 +976,7 @@ public class DateUtils {
                                 val.add(Calendar.HOUR_OF_DAY, -12);
                                 val.add(Calendar.DATE, 1);
                             }
-// ----------------- Fix for LANG-440 ---------------------- END ---------------
+                            // Fix for LANG-440 END
                         } else {
                             //We need at add one to this field since the
                             //  last number causes us to round up