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 2025/08/20 22:24:16 UTC

(commons-lang) branch master updated (df51dfb80 -> d45f23e95)

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 df51dfb80 Javadoc
     new d8aeb514e Javadoc
     new d385969c5 Javadoc
     new 501915295 Add org.apache.commons.lang3.concurrent.ConcurrentException.ConcurrentException(String)
     new 0f211efaf org.apache.commons.lang3.concurrent.AtomicSafeInitializer.get() can spin internally if the FailableSupplier given to org.apache.commons.lang3.concurrent.AbstractConcurrentInitializer.AbstractBuilder.setInitializer(FailableSupplier) throws a RuntimeException
     new eaf4d61f6 Sort members
     new d5758118b Sort members
     new d45f23e95 Refactor some exception tests

The 7 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                            |   2 +
 .../java/org/apache/commons/lang3/StringUtils.java |  96 ++++++++---------
 .../concurrent/AbstractConcurrentInitializer.java  |   9 +-
 .../lang3/concurrent/AtomicInitializer.java        |  14 +--
 .../lang3/concurrent/AtomicSafeInitializer.java    |  13 ++-
 .../concurrent/CallableBackgroundInitializer.java  |  32 +++---
 .../lang3/concurrent/ConcurrentException.java      |  11 ++
 .../commons/lang3/concurrent/LazyInitializer.java  |   6 +-
 .../concurrent/MultiBackgroundInitializer.java     | 120 +++++++++------------
 .../apache/commons/lang3/reflect/MethodUtils.java  |  48 ++++-----
 .../lang3/StringUtilsEqualsIndexOfTest.java        |  22 ++--
 ...oncurrentInitializerCloseAndExceptionsTest.java |  15 ++-
 .../concurrent/AtomicSafeInitializerTest.java      |  44 +++++++-
 .../concurrent/BackgroundInitializerTest.java      |   4 +-
 .../ConcurrentExceptionTest.java}                  |  38 +++++--
 .../ConcurrentRuntimeExceptionTest.java}           |  34 +++---
 .../lang3/concurrent/ConcurrentUtilsTest.java      |  50 +--------
 17 files changed, 275 insertions(+), 283 deletions(-)
 copy src/test/java/org/apache/commons/lang3/{builder/ConversionTest.java => concurrent/ConcurrentExceptionTest.java} (50%)
 copy src/test/java/org/apache/commons/lang3/{builder/ConversionTest.java => concurrent/ConcurrentRuntimeExceptionTest.java} (55%)


(commons-lang) 05/07: Sort members

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 eaf4d61f6b0f0c52d6065a8be080677056387dd9
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Wed Aug 20 18:20:31 2025 -0400

    Sort members
---
 .../lang3/StringUtilsEqualsIndexOfTest.java        | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java
index 26409ac2c..98a292e9e 100644
--- a/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java
+++ b/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java
@@ -402,6 +402,17 @@ void testIndexOfAny_StringCharArray() {
         assertEquals(0, StringUtils.indexOfAny("cbda", 'a', 'b', 'c', 'd'));
     }
 
+    /**
+     * See https://www.oracle.com/technical-resources/articles/javase/supplementary.html
+     */
+    @Test
+    void testIndexOfAny_StringCharArrayWithSupplementaryChars() {
+        assertEquals(0, StringUtils.indexOfAny(CharU20000 + CharU20001, CharU20000.toCharArray()));
+        assertEquals(2, StringUtils.indexOfAny(CharU20000 + CharU20001, CharU20001.toCharArray()));
+        assertEquals(0, StringUtils.indexOfAny(CharU20000, CharU20000.toCharArray()));
+        assertEquals(-1, StringUtils.indexOfAny(CharU20000, CharU20001.toCharArray()));
+    }
+
     @Test
     void testIndexOfAny_StringIntCharArray() {
         // default cases
@@ -438,17 +449,6 @@ void testIndexOfAny_StringIntCharArray() {
         assertEquals(1, StringUtils.indexOfAny("cbda", 1, 'a', 'b', 'c', 'd'));
     }
 
-    /**
-     * See https://www.oracle.com/technical-resources/articles/javase/supplementary.html
-     */
-    @Test
-    void testIndexOfAny_StringCharArrayWithSupplementaryChars() {
-        assertEquals(0, StringUtils.indexOfAny(CharU20000 + CharU20001, CharU20000.toCharArray()));
-        assertEquals(2, StringUtils.indexOfAny(CharU20000 + CharU20001, CharU20001.toCharArray()));
-        assertEquals(0, StringUtils.indexOfAny(CharU20000, CharU20000.toCharArray()));
-        assertEquals(-1, StringUtils.indexOfAny(CharU20000, CharU20001.toCharArray()));
-    }
-
     @Test
     void testIndexOfAny_StringString() {
         assertEquals(-1, StringUtils.indexOfAny(null, (String) null));


(commons-lang) 03/07: Add org.apache.commons.lang3.concurrent.ConcurrentException.ConcurrentException(String)

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 5019152951ad0d9fe65961b5f6e0d1527f876bd5
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Wed Aug 20 18:14:14 2025 -0400

    Add org.apache.commons.lang3.concurrent.ConcurrentException.ConcurrentException(String)
---
 src/changes/changes.xml                                       |  1 +
 .../apache/commons/lang3/concurrent/ConcurrentException.java  | 11 +++++++++++
 .../apache/commons/lang3/concurrent/ConcurrentUtilsTest.java  |  8 +++++++-
 3 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 305fcc4e2..7eb7038ba 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -65,6 +65,7 @@ The <action> type attribute can be add,update,fix,remove.
     <action                   type="add" dev="ggregory" due-to="Gary Gregory">Add org.apache.commons.lang3.reflect.MethodUtils.getAccessibleMethod(Class, Method).</action>
     <action                   type="add" dev="ggregory" due-to="Gary Gregory">Add documentation to site for CVE-2025-48924 ClassUtils.getClass(...) can throw a StackOverflowError on very long inputs.</action>
     <action                   type="add" dev="ggregory" due-to="Gary Gregory">Add org.apache.commons.lang3.StringUtils.indexOfAny(CharSequence, int, char...).</action>
+    <action                   type="add" dev="ggregory" due-to="Gary Gregory">Add org.apache.commons.lang3.concurrent.ConcurrentException.ConcurrentException(String).</action>
     <!-- UPDATE -->
     <action type="update" dev="ggregory" due-to="Gary Gregory">[test] Bump org.apache.commons:commons-text from 1.13.1 to 1.14.0.</action>
   </release>
diff --git a/src/main/java/org/apache/commons/lang3/concurrent/ConcurrentException.java b/src/main/java/org/apache/commons/lang3/concurrent/ConcurrentException.java
index 28514d548..8b25a92fd 100644
--- a/src/main/java/org/apache/commons/lang3/concurrent/ConcurrentException.java
+++ b/src/main/java/org/apache/commons/lang3/concurrent/ConcurrentException.java
@@ -41,6 +41,17 @@ public class ConcurrentException extends Exception {
     protected ConcurrentException() {
     }
 
+    /**
+     * Constructs a new exception with the specified detail message. The cause is not initialized, and may subsequently be initialized by a call to
+     * {@link #initCause}.
+     *
+     * @param message the detail message. The detail message is saved for later retrieval by the {@link #getMessage()} method.
+     * @since 3.19.0
+     */
+    public ConcurrentException(final String message) {
+        super(message);
+    }
+
     /**
      * Creates a new instance of {@link ConcurrentException} and initializes it
      * with the given message and cause.
diff --git a/src/test/java/org/apache/commons/lang3/concurrent/ConcurrentUtilsTest.java b/src/test/java/org/apache/commons/lang3/concurrent/ConcurrentUtilsTest.java
index 6b074d53a..8e12f3061 100644
--- a/src/test/java/org/apache/commons/lang3/concurrent/ConcurrentUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/concurrent/ConcurrentUtilsTest.java
@@ -52,7 +52,13 @@ void testConcurrentExceptionCauseError() {
      */
     @Test
     void testConcurrentExceptionCauseNull() {
-        assertIllegalArgumentException(() -> new ConcurrentException(null));
+        assertIllegalArgumentException(() -> new ConcurrentException((Throwable) null));
+    }
+
+    @Test
+    void testConcurrentExceptionCauseString() {
+        assertEquals("test", new ConcurrentException("test").getMessage());
+        assertNull(new ConcurrentException((String) null).getMessage());
     }
 
     /**


(commons-lang) 02/07: 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 d385969c523508ac5de9503f600ae1998e42224b
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Wed Aug 20 16:51:24 2025 -0400

    Javadoc
    
    Reduce vertical whitespace
---
 .../lang3/concurrent/AtomicInitializer.java        |  14 +--
 .../concurrent/CallableBackgroundInitializer.java  |  32 +++---
 .../commons/lang3/concurrent/LazyInitializer.java  |   6 +-
 .../concurrent/MultiBackgroundInitializer.java     | 120 +++++++++------------
 .../concurrent/BackgroundInitializerTest.java      |   4 +-
 5 files changed, 70 insertions(+), 106 deletions(-)

diff --git a/src/main/java/org/apache/commons/lang3/concurrent/AtomicInitializer.java b/src/main/java/org/apache/commons/lang3/concurrent/AtomicInitializer.java
index a1c88a155..649ea161d 100644
--- a/src/main/java/org/apache/commons/lang3/concurrent/AtomicInitializer.java
+++ b/src/main/java/org/apache/commons/lang3/concurrent/AtomicInitializer.java
@@ -62,7 +62,7 @@
  * {@link LazyInitializer} is more appropriate.
  * </p>
  *
- * @param <T> the type of the object managed by this initializer class
+ * @param <T> the type of the object managed by this initializer class.
  * @since 3.0
  */
 public class AtomicInitializer<T> extends AbstractConcurrentInitializer<T, ConcurrentException> {
@@ -125,18 +125,15 @@ private AtomicInitializer(final FailableSupplier<T, ConcurrentException> initial
     }
 
     /**
-     * Gets the object managed by this initializer. The object is created if
-     * it is not available yet and stored internally. This method always returns
-     * the same object.
+     * Gets the object managed by this initializer. The object is created if it is not available yet and stored internally. This method always returns the same
+     * object.
      *
-     * @return the object created by this {@link AtomicInitializer}
-     * @throws ConcurrentException if an error occurred during initialization of
-     * the object
+     * @return the object created by this {@link AtomicInitializer}.
+     * @throws ConcurrentException if an error occurred during initialization of the object.
      */
     @Override
     public T get() throws ConcurrentException {
         T result = reference.get();
-
         if (result == getNoInit()) {
             result = initialize();
             if (!reference.compareAndSet(getNoInit(), result)) {
@@ -144,7 +141,6 @@ public T get() throws ConcurrentException {
                 result = reference.get();
             }
         }
-
         return result;
     }
 
diff --git a/src/main/java/org/apache/commons/lang3/concurrent/CallableBackgroundInitializer.java b/src/main/java/org/apache/commons/lang3/concurrent/CallableBackgroundInitializer.java
index 42bdd1e0b..20fa6b03a 100644
--- a/src/main/java/org/apache/commons/lang3/concurrent/CallableBackgroundInitializer.java
+++ b/src/main/java/org/apache/commons/lang3/concurrent/CallableBackgroundInitializer.java
@@ -72,8 +72,8 @@ public class CallableBackgroundInitializer<T> extends BackgroundInitializer<T> {
      * Creates a new instance of {@link CallableBackgroundInitializer} and sets
      * the {@link Callable} to be executed in a background thread.
      *
-     * @param call the {@link Callable} (must not be <strong>null</strong>)
-     * @throws IllegalArgumentException if the {@link Callable} is <strong>null</strong>
+     * @param call the {@link Callable} (must not be <strong>null</strong>).
+     * @throws IllegalArgumentException if the {@link Callable} is <strong>null</strong>.
      */
     public CallableBackgroundInitializer(final Callable<T> call) {
         checkCallable(call);
@@ -81,15 +81,12 @@ public CallableBackgroundInitializer(final Callable<T> call) {
     }
 
     /**
-     * Creates a new instance of {@link CallableBackgroundInitializer} and
-     * initializes it with the {@link Callable} to be executed in a background
-     * thread and the {@link ExecutorService} for managing the background
-     * execution.
+     * Creates a new instance of {@link CallableBackgroundInitializer} and initializes it with the {@link Callable} to be executed in a background thread and
+     * the {@link ExecutorService} for managing the background execution.
      *
-     * @param call the {@link Callable} (must not be <strong>null</strong>)
-     * @param exec an external {@link ExecutorService} to be used for task
-     * execution
-     * @throws IllegalArgumentException if the {@link Callable} is <strong>null</strong>
+     * @param call the {@link Callable} (must not be <strong>null</strong>).
+     * @param exec an external {@link ExecutorService} to be used for task execution.
+     * @throws IllegalArgumentException if the {@link Callable} is <strong>null</strong>.
      */
     public CallableBackgroundInitializer(final Callable<T> call, final ExecutorService exec) {
         super(exec);
@@ -98,11 +95,10 @@ public CallableBackgroundInitializer(final Callable<T> call, final ExecutorServi
     }
 
     /**
-     * Tests the passed in {@link Callable} and throws an exception if it is
-     * undefined.
+     * Tests the passed in {@link Callable} and throws an exception if it is undefined.
      *
-     * @param callable the object to check
-     * @throws IllegalArgumentException if the {@link Callable} is <strong>null</strong>
+     * @param callable the object to check.
+     * @throws IllegalArgumentException if the {@link Callable} is <strong>null</strong>.
      */
     private void checkCallable(final Callable<T> callable) {
         Objects.requireNonNull(callable, "callable");
@@ -118,12 +114,10 @@ protected Exception getTypedException(final Exception e) {
     }
 
     /**
-     * Performs initialization in a background thread. This implementation
-     * delegates to the {@link Callable} passed at construction time of this
-     * object.
+     * Performs initialization in a background thread. This implementation delegates to the {@link Callable} passed at construction time of this object.
      *
-     * @return the result of the initialization
-     * @throws Exception if an error occurs
+     * @return the result of the initialization.
+     * @throws Exception if an error occurs.
      */
     @Override
     protected T initialize() throws Exception {
diff --git a/src/main/java/org/apache/commons/lang3/concurrent/LazyInitializer.java b/src/main/java/org/apache/commons/lang3/concurrent/LazyInitializer.java
index 2d4cab13e..a5271eba6 100644
--- a/src/main/java/org/apache/commons/lang3/concurrent/LazyInitializer.java
+++ b/src/main/java/org/apache/commons/lang3/concurrent/LazyInitializer.java
@@ -135,15 +135,14 @@ private LazyInitializer(final FailableSupplier<T, ConcurrentException> initializ
     /**
      * Gets the object wrapped by this instance. On first access the object is created. After that it is cached and can be accessed pretty fast.
      *
-     * @return the object initialized by this {@link LazyInitializer}
-     * @throws ConcurrentException if an error occurred during initialization of the object
+     * @return the object initialized by this {@link LazyInitializer}.
+     * @throws ConcurrentException if an error occurred during initialization of the object.
      */
     @Override
     public T get() throws ConcurrentException {
         // use a temporary variable to reduce the number of reads of the
         // volatile field
         T result = object;
-
         if (result == NO_INIT) {
             synchronized (this) {
                 result = object;
@@ -152,7 +151,6 @@ public T get() throws ConcurrentException {
                 }
             }
         }
-
         return result;
     }
 
diff --git a/src/main/java/org/apache/commons/lang3/concurrent/MultiBackgroundInitializer.java b/src/main/java/org/apache/commons/lang3/concurrent/MultiBackgroundInitializer.java
index e1ce1f84c..631078394 100644
--- a/src/main/java/org/apache/commons/lang3/concurrent/MultiBackgroundInitializer.java
+++ b/src/main/java/org/apache/commons/lang3/concurrent/MultiBackgroundInitializer.java
@@ -93,9 +93,7 @@
  *
  * @since 3.0
  */
-public class MultiBackgroundInitializer
-        extends
-        BackgroundInitializer<MultiBackgroundInitializer.MultiBackgroundInitializerResults> {
+public class MultiBackgroundInitializer extends BackgroundInitializer<MultiBackgroundInitializer.MultiBackgroundInitializerResults> {
 
     /**
      * A data class for storing the results of the background initialization
@@ -118,21 +116,18 @@ public static class MultiBackgroundInitializerResults {
         private final Map<String, ConcurrentException> exceptions;
 
         /**
-         * Creates a new instance of {@link MultiBackgroundInitializerResults}
-         * and initializes it with maps for the {@link BackgroundInitializer}
-         * objects, their result objects and the exceptions thrown by them.
+         * Creates a new instance of {@link MultiBackgroundInitializerResults} and initializes it with maps for the {@link BackgroundInitializer} objects, their
+         * result objects and the exceptions thrown by them.
          *
-         * @param inits the {@link BackgroundInitializer} objects
-         * @param results the result objects
-         * @param excepts the exceptions
+         * @param initializers  the {@link BackgroundInitializer} objects.
+         * @param resultObjects the result objects.
+         * @param exceptions    the exceptions.
          */
-        private MultiBackgroundInitializerResults(
-                final Map<String, BackgroundInitializer<?>> inits,
-                final Map<String, Object> results,
-                final Map<String, ConcurrentException> excepts) {
-            initializers = inits;
-            resultObjects = results;
-            exceptions = excepts;
+        private MultiBackgroundInitializerResults(final Map<String, BackgroundInitializer<?>> initializers, final Map<String, Object> resultObjects,
+                final Map<String, ConcurrentException> exceptions) {
+            this.initializers = initializers;
+            this.resultObjects = resultObjects;
+            this.exceptions = exceptions;
         }
 
         /**
@@ -140,17 +135,15 @@ private MultiBackgroundInitializerResults(
          * throws an exception. If it exists, the associated child initializer
          * is returned.
          *
-         * @param name the name to check
-         * @return the initializer with this name
-         * @throws NoSuchElementException if the name is unknown
+         * @param name the name to check.
+         * @return the initializer with this name.
+         * @throws NoSuchElementException if the name is unknown.
          */
         private BackgroundInitializer<?> checkName(final String name) {
             final BackgroundInitializer<?> init = initializers.get(name);
             if (init == null) {
-                throw new NoSuchElementException(
-                        "No child initializer with name " + name);
+                throw new NoSuchElementException("No child initializer with name " + name);
             }
-
             return init;
         }
 
@@ -160,9 +153,9 @@ private BackgroundInitializer<?> checkName(final String name) {
          * initializer did not throw an exception, the return value is
          * <strong>null</strong>. If the name cannot be resolved, an exception is thrown.
          *
-         * @param name the name of the {@link BackgroundInitializer}
-         * @return the exception thrown by this initializer
-         * @throws NoSuchElementException if the name cannot be resolved
+         * @param name the name of the {@link BackgroundInitializer}.
+         * @return the exception thrown by this initializer.
+         * @throws NoSuchElementException if the name cannot be resolved.
          */
         public ConcurrentException getException(final String name) {
             checkName(name);
@@ -173,9 +166,9 @@ public ConcurrentException getException(final String name) {
          * Gets the {@link BackgroundInitializer} with the given name. If the
          * name cannot be resolved, an exception is thrown.
          *
-         * @param name the name of the {@link BackgroundInitializer}
-         * @return the {@link BackgroundInitializer} with this name
-         * @throws NoSuchElementException if the name cannot be resolved
+         * @param name the name of the {@link BackgroundInitializer}.
+         * @return the {@link BackgroundInitializer} with this name.
+         * @throws NoSuchElementException if the name cannot be resolved.
          */
         public BackgroundInitializer<?> getInitializer(final String name) {
             return checkName(name);
@@ -183,15 +176,12 @@ public BackgroundInitializer<?> getInitializer(final String name) {
 
         /**
          * Gets the result object produced by the {@code
-         * BackgroundInitializer} with the given name. This is the object
-         * returned by the initializer's {@code initialize()} method. If this
-         * {@link BackgroundInitializer} caused an exception, <strong>null</strong> is
-         * returned. If the name cannot be resolved, an exception is thrown.
+         * BackgroundInitializer} with the given name. This is the object returned by the initializer's {@code initialize()} method. If this
+         * {@link BackgroundInitializer} caused an exception, <strong>null</strong> is returned. If the name cannot be resolved, an exception is thrown.
          *
-         * @param name the name of the {@link BackgroundInitializer}
-         * @return the result object produced by this {@code
-         * BackgroundInitializer}
-         * @throws NoSuchElementException if the name cannot be resolved
+         * @param name the name of the {@link BackgroundInitializer}.
+         * @return the result object produced by this {@code BackgroundInitializer}.
+         * @throws NoSuchElementException if the name cannot be resolved.
          */
         public Object getResultObject(final String name) {
             checkName(name);
@@ -199,11 +189,9 @@ public Object getResultObject(final String name) {
         }
 
         /**
-         * Returns a set with the names of all {@link BackgroundInitializer}
-         * objects managed by the {@link MultiBackgroundInitializer}.
+         * Returns a set with the names of all {@link BackgroundInitializer} objects managed by the {@link MultiBackgroundInitializer}.
          *
-         * @return an (unmodifiable) set with the names of the managed {@code
-         * BackgroundInitializer} objects
+         * @return an (unmodifiable) set with the names of the managed {@code BackgroundInitializer} objects.
          */
         public Set<String> initializerNames() {
             return Collections.unmodifiableSet(initializers.keySet());
@@ -213,9 +201,9 @@ public Set<String> initializerNames() {
          * Tests whether the {@link BackgroundInitializer} with the
          * given name caused an exception.
          *
-         * @param name the name of the {@link BackgroundInitializer}
-         * @return a flag whether this initializer caused an exception
-         * @throws NoSuchElementException if the name cannot be resolved
+         * @param name the name of the {@link BackgroundInitializer}.
+         * @return a flag whether this initializer caused an exception.
+         * @throws NoSuchElementException if the name cannot be resolved.
          */
         public boolean isException(final String name) {
             checkName(name);
@@ -226,7 +214,7 @@ public boolean isException(final String name) {
          * Tests whether the whole initialization was successful. This
          * is the case if no child initializer has thrown an exception.
          *
-         * @return a flag whether the initialization was successful
+         * @return a flag whether the initialization was successful.
          */
         public boolean isSuccessful() {
             return exceptions.isEmpty();
@@ -246,30 +234,24 @@ public MultiBackgroundInitializer() {
      * Constructs a new instance of {@link MultiBackgroundInitializer} and
      * initializes it with the given external {@link ExecutorService}.
      *
-     * @param exec the {@link ExecutorService} for executing the background
-     * tasks
+     * @param exec the {@link ExecutorService} for executing the background tasks.
      */
     public MultiBackgroundInitializer(final ExecutorService exec) {
         super(exec);
     }
 
     /**
-     * Adds a new {@link BackgroundInitializer} to this object. When this
-     * {@link MultiBackgroundInitializer} is started, the given initializer will
-     * be processed. This method must not be called after {@link #start()} has
-     * been invoked.
+     * Adds a new {@link BackgroundInitializer} to this object. When this {@link MultiBackgroundInitializer} is started, the given initializer will be
+     * processed. This method must not be called after {@link #start()} has been invoked.
      *
-     * @param name the name of the initializer (must not be <strong>null</strong>)
-     * @param backgroundInitializer the {@link BackgroundInitializer} to add (must not be
-     * <strong>null</strong>)
-     * @throws NullPointerException if either {@code name} or {@code backgroundInitializer}
-     *         is {@code null}
-     * @throws IllegalStateException if {@code start()} has already been called
+     * @param name                  the name of the initializer (must not be <strong>null</strong>).
+     * @param backgroundInitializer the {@link BackgroundInitializer} to add (must not be <strong>null</strong>).
+     * @throws NullPointerException  if either {@code name} or {@code backgroundInitializer} is {@code null}.
+     * @throws IllegalStateException if {@code start()} has already been called.
      */
     public void addInitializer(final String name, final BackgroundInitializer<?> backgroundInitializer) {
         Objects.requireNonNull(name, "name");
         Objects.requireNonNull(backgroundInitializer, "backgroundInitializer");
-
         synchronized (this) {
             if (isStarted()) {
                 throw new IllegalStateException("addInitializer() must not be called after start()!");
@@ -279,15 +261,15 @@ public void addInitializer(final String name, final BackgroundInitializer<?> bac
     }
 
     /**
-     * Calls the closer of all child {@code BackgroundInitializer} objects
+     * Calls the closer of all child {@code BackgroundInitializer} objects.
      *
-     * @throws ConcurrentException throws an ConcurrentException that will have all other exceptions as suppressed exceptions. ConcurrentException thrown by children will be unwrapped.
+     * @throws ConcurrentException throws an ConcurrentException that will have all other exceptions as suppressed exceptions. ConcurrentException thrown by
+     *                             children will be unwrapped.
      * @since 3.14.0
      */
     @Override
     public void close() throws ConcurrentException {
         ConcurrentException exception = null;
-
         for (final BackgroundInitializer<?> child : childInitializers.values()) {
             try {
                 child.close();
@@ -295,7 +277,6 @@ public void close() throws ConcurrentException {
                 if (exception == null) {
                     exception = new ConcurrentException();
                 }
-
                 if (e instanceof ConcurrentException) {
                     // Because ConcurrentException is only created by classes in this package
                     // we can safely unwrap it.
@@ -305,7 +286,6 @@ public void close() throws ConcurrentException {
                 }
             }
         }
-
         if (exception != null) {
             throw exception;
         }
@@ -319,7 +299,7 @@ public void close() throws ConcurrentException {
      * ). Then it adds 1 for the control task that waits for the completion of
      * the children.
      *
-     * @return the number of tasks required for background processing
+     * @return the number of tasks required for background processing.
      */
     @Override
     protected int getTaskCount() {
@@ -333,8 +313,8 @@ protected int getTaskCount() {
      * data. If a child initializer throws a checked exceptions, it is added to
      * the results object. Unchecked exceptions are propagated.
      *
-     * @return the results object
-     * @throws Exception if an error occurs
+     * @return the results object.
+     * @throws Exception if an error occurs.
      */
     @Override
     protected MultiBackgroundInitializerResults initialize() throws Exception {
@@ -343,7 +323,6 @@ protected MultiBackgroundInitializerResults initialize() throws Exception {
             // create a snapshot to operate on
             inits = new HashMap<>(childInitializers);
         }
-
         // start the child initializers
         final ExecutorService exec = getActiveExecutor();
         inits.values().forEach(bi -> {
@@ -353,7 +332,6 @@ protected MultiBackgroundInitializerResults initialize() throws Exception {
             }
             bi.start();
         });
-
         // collect the results
         final Map<String, Object> results = new HashMap<>();
         final Map<String, ConcurrentException> excepts = new HashMap<>();
@@ -364,15 +342,14 @@ protected MultiBackgroundInitializerResults initialize() throws Exception {
                 excepts.put(k, cex);
             }
         });
-
         return new MultiBackgroundInitializerResults(inits, results, excepts);
     }
 
     /**
-     * Tests whether this all child {@code BackgroundInitializer} objects are initialized.
-     * Once initialized, always returns true.
+     * Tests whether this all child {@code BackgroundInitializer} objects are initialized. Once initialized, always returns true.
      *
-     * @return whether all child {@code BackgroundInitializer} objects instance are initialized. Once initialized, always returns true. If there are no child {@code BackgroundInitializer} objects return false.
+     * @return Whether all child {@code BackgroundInitializer} objects instance are initialized. Once initialized, always returns true. If there are no child
+     *         {@code BackgroundInitializer} objects return false.
      * @since 3.14.0
      */
     @Override
@@ -380,7 +357,6 @@ public boolean isInitialized() {
         if (childInitializers.isEmpty()) {
             return false;
         }
-
         return childInitializers.values().stream().allMatch(BackgroundInitializer::isInitialized);
     }
 }
diff --git a/src/test/java/org/apache/commons/lang3/concurrent/BackgroundInitializerTest.java b/src/test/java/org/apache/commons/lang3/concurrent/BackgroundInitializerTest.java
index 0034b7deb..f167cacb3 100644
--- a/src/test/java/org/apache/commons/lang3/concurrent/BackgroundInitializerTest.java
+++ b/src/test/java/org/apache/commons/lang3/concurrent/BackgroundInitializerTest.java
@@ -76,7 +76,7 @@ public CloseableCounter getCloseableCounter() {
          * Records this invocation. Optionally throws an exception or sleeps a
          * while.
          *
-         * @throws Exception in case of an error
+         * @throws Exception in case of an error.
          */
         protected CloseableCounter initializeInternal() throws Exception {
             if (ex != null) {
@@ -140,7 +140,7 @@ protected CloseableCounter initialize() throws Exception {
      * Helper method for checking whether the initialize() method was correctly
      * called. start() must already have been invoked.
      *
-     * @param init the initializer to test
+     * @param init the initializer to test.
      */
     private void checkInitialize(final AbstractBackgroundInitializerTestImpl init) throws ConcurrentException {
         final Integer result = init.get().getInitializeCalls();


(commons-lang) 04/07: org.apache.commons.lang3.concurrent.AtomicSafeInitializer.get() can spin internally if the FailableSupplier given to org.apache.commons.lang3.concurrent.AbstractConcurrentInitializer.AbstractBuilder.setInitializer(FailableSupplier) throws a RuntimeException

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 0f211efaf1228c3371b2a81de095661a94907f5e
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Wed Aug 20 18:14:44 2025 -0400

    org.apache.commons.lang3.concurrent.AtomicSafeInitializer.get() can spin
    internally if the FailableSupplier given to
    org.apache.commons.lang3.concurrent.AbstractConcurrentInitializer.AbstractBuilder.setInitializer(FailableSupplier)
    throws a RuntimeException
---
 src/changes/changes.xml                            |  1 +
 .../lang3/concurrent/AtomicSafeInitializer.java    | 13 +++++--
 ...oncurrentInitializerCloseAndExceptionsTest.java | 15 +++-----
 .../concurrent/AtomicSafeInitializerTest.java      | 44 ++++++++++++++++++++--
 4 files changed, 57 insertions(+), 16 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 7eb7038ba..1e9fe0b76 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -50,6 +50,7 @@ The <action> type attribute can be add,update,fix,remove.
     <action                   type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.commons.lang3.reflect.MethodUtils.getMethodObject(Class&lt;?&gt;, String, Class&lt;?&gt;...) now returns null instead of throwing a NullPointerException, as it does for other exception types.</action>
     <action                   type="fix" dev="ggregory" due-to="Gary Gregory">Reduce spurious failures in org.apache.commons.lang3.ArrayUtilsTest methods that test ArrayUtils.shuffle() methods.</action>
     <action                   type="fix" dev="ggregory" due-to="Gary Gregory">MethodUtils cannot find or invoke a public method on a public class implemented in its package-private superclass.</action>
+    <action                   type="fix" dev="ggregory" due-to="Stanislav Fort, Gary Gregory">org.apache.commons.lang3.concurrent.AtomicSafeInitializer.get() can spin internally if the FailableSupplier given to org.apache.commons.lang3.concurrent.AbstractConcurrentInitializer.AbstractBuilder.setInitializer(FailableSupplier) throws a RuntimeException.</action>
     <!-- FIX Javadoc -->
     <action                   type="fix" dev="ggregory" due-to="Gary Gregory">[javadoc] General improvements.</action>
     <action                   type="fix" dev="ggregory" due-to="Gary Gregory">[javadoc] Fix thrown exception documentation for org.apache.commons.lang3.reflect.MethodUtils.getMethodObject(Class&lt;?&gt;, String, Class&lt;?&gt;...).</action>
diff --git a/src/main/java/org/apache/commons/lang3/concurrent/AtomicSafeInitializer.java b/src/main/java/org/apache/commons/lang3/concurrent/AtomicSafeInitializer.java
index cd2672851..dce8cccdb 100644
--- a/src/main/java/org/apache/commons/lang3/concurrent/AtomicSafeInitializer.java
+++ b/src/main/java/org/apache/commons/lang3/concurrent/AtomicSafeInitializer.java
@@ -18,6 +18,7 @@
 
 import java.util.concurrent.atomic.AtomicReference;
 
+import org.apache.commons.lang3.exception.ExceptionUtils;
 import org.apache.commons.lang3.function.FailableConsumer;
 import org.apache.commons.lang3.function.FailableSupplier;
 
@@ -125,13 +126,19 @@ private AtomicSafeInitializer(final FailableSupplier<T, ConcurrentException> ini
     @Override
     public final T get() throws ConcurrentException {
         T result;
-
         while ((result = reference.get()) == getNoInit()) {
             if (factory.compareAndSet(null, this)) {
-                reference.set(initialize());
+                try {
+                    reference.set(initialize());
+                } catch (final Throwable t) {
+                    // Allow retry on failure; otherwise callers spin forever.
+                    factory.set(null);
+                    // Rethrow preserving original semantics: unchecked as-is, checked wrapped.
+                    final Throwable checked = ExceptionUtils.throwUnchecked(t);
+                    throw checked instanceof ConcurrentException ? (ConcurrentException) checked : new ConcurrentException(checked);
+                }
             }
         }
-
         return result;
     }
 
diff --git a/src/test/java/org/apache/commons/lang3/concurrent/AbstractConcurrentInitializerCloseAndExceptionsTest.java b/src/test/java/org/apache/commons/lang3/concurrent/AbstractConcurrentInitializerCloseAndExceptionsTest.java
index 5d58d7c6e..e8a7eb36f 100644
--- a/src/test/java/org/apache/commons/lang3/concurrent/AbstractConcurrentInitializerCloseAndExceptionsTest.java
+++ b/src/test/java/org/apache/commons/lang3/concurrent/AbstractConcurrentInitializerCloseAndExceptionsTest.java
@@ -137,16 +137,13 @@ void testSupplierThrowsCheckedException() {
     @Test
     void testSupplierThrowsConcurrentException() {
         final ConcurrentException concurrentException = new ConcurrentException();
-
         @SuppressWarnings("unchecked")
-        final ConcurrentInitializer<CloseableObject> initializer = createInitializerThatThrowsException(
-                () -> {
-                    if ("test".equals("test")) {
-                        throw concurrentException;
-                    }
-                    return new CloseableObject();
-                },
-                FailableConsumer.NOP);
+        final ConcurrentInitializer<CloseableObject> initializer = createInitializerThatThrowsException(() -> {
+            if ("test".equals("test")) {
+                throw concurrentException;
+            }
+            return new CloseableObject();
+        }, FailableConsumer.NOP);
         try {
             initializer.get();
             fail();
diff --git a/src/test/java/org/apache/commons/lang3/concurrent/AtomicSafeInitializerTest.java b/src/test/java/org/apache/commons/lang3/concurrent/AtomicSafeInitializerTest.java
index f4cf6d5e0..94b4a8c3a 100644
--- a/src/test/java/org/apache/commons/lang3/concurrent/AtomicSafeInitializerTest.java
+++ b/src/test/java/org/apache/commons/lang3/concurrent/AtomicSafeInitializerTest.java
@@ -14,16 +14,26 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package org.apache.commons.lang3.concurrent;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
+import java.io.IOException;
+import java.nio.file.FileSystemException;
+import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import org.apache.commons.lang3.exception.ExceptionUtils;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
+import org.junit.jupiter.api.Timeout.ThreadMode;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
 
 /**
  * Test class for {@code AtomicSafeInitializer} which also serves as a simple example.
@@ -37,6 +47,7 @@ class AtomicSafeInitializerTest extends AbstractConcurrentInitializerTest<Object
      * </p>
      */
     private static final class AtomicSafeInitializerTestImpl extends AtomicSafeInitializer<Object> {
+
         /** A counter for initialize() invocations. */
         final AtomicInteger initCounter = new AtomicInteger();
 
@@ -53,7 +64,7 @@ protected Object initialize() {
     /**
      * Returns the initializer to be tested.
      *
-     * @return the {@code AtomicSafeInitializer} under test
+     * @return the {@code AtomicSafeInitializer} under test.
      */
     @Override
     protected ConcurrentInitializer<Object> createInitializer() {
@@ -68,6 +79,7 @@ public void setUp() {
     @Test
     void testGetThatReturnsNullFirstTime() throws ConcurrentException {
         final AtomicSafeInitializer<Object> initializer = new AtomicSafeInitializer<Object>() {
+
             final AtomicBoolean firstRun = new AtomicBoolean(true);
 
             @Override
@@ -78,16 +90,40 @@ protected Object initialize() {
                 return new Object();
             }
         };
-
         assertNull(initializer.get());
         assertNull(initializer.get());
     }
 
+    @ParameterizedTest
+    @ValueSource(classes = { IOException.class, Exception.class, FileSystemException.class, ReflectiveOperationException.class, ConcurrentException.class })
+    @Timeout(value = 5, unit = TimeUnit.SECONDS, threadMode = ThreadMode.SAME_THREAD)
+    void testInitializerThrowsChecked(final Class<Exception> throwableClass) throws ConcurrentException {
+        final String message = "Initializing";
+        final AtomicSafeInitializer<Object> asi = AtomicSafeInitializer.builder().setInitializer(() -> {
+            throw throwableClass.getConstructor(String.class).newInstance(message);
+        }).get();
+        final String expected = throwableClass.getSimpleName() + ": " + message;
+        assertEquals(expected, ExceptionUtils.getRootCauseMessage(assertThrows(ConcurrentException.class, asi::get)));
+        assertEquals(expected, ExceptionUtils.getRootCauseMessage(assertThrows(ConcurrentException.class, asi::get)));
+    }
+
+    @ParameterizedTest
+    @ValueSource(classes = { IllegalStateException.class, IllegalArgumentException.class, NullPointerException.class, RuntimeException.class })
+    @Timeout(value = 5, unit = TimeUnit.SECONDS, threadMode = ThreadMode.SAME_THREAD)
+    void testInitializerThrowsUnchecked(final Class<Exception> throwableClass) throws ConcurrentException {
+        final String message = "Initializing";
+        final AtomicSafeInitializer<Object> asi = AtomicSafeInitializer.builder().setInitializer(() -> {
+            throw throwableClass.getConstructor(String.class).newInstance(message);
+        }).get();
+        assertEquals(message, assertThrows(throwableClass, asi::get).getMessage());
+        assertEquals(message, assertThrows(throwableClass, asi::get).getMessage());
+    }
+
     /**
      * Tests that initialize() is called only once.
      *
-     * @throws org.apache.commons.lang3.concurrent.ConcurrentException because {@link #testGetConcurrent()} may throw it
-     * @throws InterruptedException because {@link #testGetConcurrent()} may throw it
+     * @throws org.apache.commons.lang3.concurrent.ConcurrentException because {@link #testGetConcurrent()} may throw it.
+     * @throws InterruptedException                                    because {@link #testGetConcurrent()} may throw it.
      */
     @Test
     void testNumberOfInitializeInvocations() throws ConcurrentException, InterruptedException {


(commons-lang) 07/07: Refactor some exception tests

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 d45f23e9579196e552afda6eb6baccf8d782c640
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Wed Aug 20 18:24:10 2025 -0400

    Refactor some exception tests
---
 .../lang3/concurrent/ConcurrentExceptionTest.java  | 60 ++++++++++++++++++++++
 .../concurrent/ConcurrentRuntimeExceptionTest.java | 52 +++++++++++++++++++
 .../lang3/concurrent/ConcurrentUtilsTest.java      | 56 +-------------------
 3 files changed, 113 insertions(+), 55 deletions(-)

diff --git a/src/test/java/org/apache/commons/lang3/concurrent/ConcurrentExceptionTest.java b/src/test/java/org/apache/commons/lang3/concurrent/ConcurrentExceptionTest.java
new file mode 100644
index 000000000..41eca1b6d
--- /dev/null
+++ b/src/test/java/org/apache/commons/lang3/concurrent/ConcurrentExceptionTest.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.concurrent;
+
+import static org.apache.commons.lang3.LangAssertions.assertIllegalArgumentException;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link ConcurrentException}.
+ */
+class ConcurrentExceptionTest {
+
+    /**
+     * Tests creating a ConcurrentException with an error as cause.
+     */
+    @Test
+    void testCauseError() {
+        assertIllegalArgumentException(() -> new ConcurrentException("An error", new Error()));
+    }
+
+    /**
+     * Tests creating a ConcurrentException with null as cause.
+     */
+    @Test
+    void testCauseNull() {
+        assertIllegalArgumentException(() -> new ConcurrentException((Throwable) null));
+    }
+
+    @Test
+    void testCauseString() {
+        assertEquals("test", new ConcurrentException("test").getMessage());
+        assertNull(new ConcurrentException((String) null).getMessage());
+    }
+
+    /**
+     * Tests creating a ConcurrentException with a runtime exception as cause.
+     */
+    @Test
+    void testCauseUnchecked() {
+        assertIllegalArgumentException(() -> new ConcurrentException(new RuntimeException()));
+    }
+}
diff --git a/src/test/java/org/apache/commons/lang3/concurrent/ConcurrentRuntimeExceptionTest.java b/src/test/java/org/apache/commons/lang3/concurrent/ConcurrentRuntimeExceptionTest.java
new file mode 100644
index 000000000..3c529dff9
--- /dev/null
+++ b/src/test/java/org/apache/commons/lang3/concurrent/ConcurrentRuntimeExceptionTest.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.concurrent;
+
+import static org.apache.commons.lang3.LangAssertions.assertIllegalArgumentException;
+
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link ConcurrentRuntimeException}.
+ */
+class ConcurrentRuntimeExceptionTest {
+
+    /**
+     * Tries to create a ConcurrentRuntimeException with an error as cause.
+     */
+    @Test
+    void testCauseError() {
+        assertIllegalArgumentException(() -> new ConcurrentRuntimeException("An error", new Error()));
+    }
+
+    /**
+     * Tries to create a ConcurrentRuntimeException with null as cause.
+     */
+    @Test
+    void testCauseNull() {
+        assertIllegalArgumentException(() -> new ConcurrentRuntimeException(null));
+    }
+
+    /**
+     * Tries to create a ConcurrentRuntimeException with a runtime as cause.
+     */
+    @Test
+    void testCauseUnchecked() {
+        assertIllegalArgumentException(() -> new ConcurrentRuntimeException(new RuntimeException()));
+    }
+}
diff --git a/src/test/java/org/apache/commons/lang3/concurrent/ConcurrentUtilsTest.java b/src/test/java/org/apache/commons/lang3/concurrent/ConcurrentUtilsTest.java
index 8e12f3061..dc925aada 100644
--- a/src/test/java/org/apache/commons/lang3/concurrent/ConcurrentUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/concurrent/ConcurrentUtilsTest.java
@@ -14,9 +14,9 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package org.apache.commons.lang3.concurrent;
 
-import static org.apache.commons.lang3.LangAssertions.assertIllegalArgumentException;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -39,60 +39,6 @@
  * Test class for {@link ConcurrentUtils}.
  */
 class ConcurrentUtilsTest extends AbstractLangTest {
-    /**
-     * Tests creating a ConcurrentException with an error as cause.
-     */
-    @Test
-    void testConcurrentExceptionCauseError() {
-        assertIllegalArgumentException(() -> new ConcurrentException("An error", new Error()));
-    }
-
-    /**
-     * Tests creating a ConcurrentException with null as cause.
-     */
-    @Test
-    void testConcurrentExceptionCauseNull() {
-        assertIllegalArgumentException(() -> new ConcurrentException((Throwable) null));
-    }
-
-    @Test
-    void testConcurrentExceptionCauseString() {
-        assertEquals("test", new ConcurrentException("test").getMessage());
-        assertNull(new ConcurrentException((String) null).getMessage());
-    }
-
-    /**
-     * Tests creating a ConcurrentException with a runtime exception as cause.
-     */
-    @Test
-    void testConcurrentExceptionCauseUnchecked() {
-        assertIllegalArgumentException(() -> new ConcurrentException(new RuntimeException()));
-    }
-
-    /**
-     * Tries to create a ConcurrentRuntimeException with an error as cause.
-     */
-    @Test
-    void testConcurrentRuntimeExceptionCauseError() {
-        assertIllegalArgumentException(() -> new ConcurrentRuntimeException("An error", new Error()));
-    }
-
-    /**
-     * Tries to create a ConcurrentRuntimeException with null as cause.
-     */
-    @Test
-    void testConcurrentRuntimeExceptionCauseNull() {
-        assertIllegalArgumentException(() -> new ConcurrentRuntimeException(null));
-    }
-
-    /**
-     * Tries to create a ConcurrentRuntimeException with a runtime as cause.
-     */
-    @Test
-    void testConcurrentRuntimeExceptionCauseUnchecked() {
-        assertIllegalArgumentException(() -> new ConcurrentRuntimeException(new RuntimeException()));
-    }
-
     /**
      * Tests constant future.
      *


(commons-lang) 06/07: Sort members

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 d5758118b5e245e052fa2378ceb76e049813d324
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Wed Aug 20 18:20:45 2025 -0400

    Sort members
---
 .../java/org/apache/commons/lang3/StringUtils.java | 96 +++++++++++-----------
 .../apache/commons/lang3/reflect/MethodUtils.java  | 48 +++++------
 2 files changed, 72 insertions(+), 72 deletions(-)

diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java
index 6c43ea3b4..116d9e16d 100644
--- a/src/main/java/org/apache/commons/lang3/StringUtils.java
+++ b/src/main/java/org/apache/commons/lang3/StringUtils.java
@@ -2708,54 +2708,6 @@ public static int indexOfAny(final CharSequence cs, final char... searchChars) {
         return indexOfAny(cs, 0, searchChars);
     }
 
-    /**
-     * Search a CharSequence to find the first index of any character in the given set of characters.
-     *
-     * <p>
-     * A {@code null} String will return {@code -1}. A {@code null} or zero length search array will return {@code -1}.
-     * </p>
-     * <p>
-     * The following is the same as {@code indexOfAny(cs, 0, searchChars)}.
-     * </p>
-     * <pre>
-     * StringUtils.indexOfAny(null, 0, *)                  = -1
-     * StringUtils.indexOfAny("", 0, *)                    = -1
-     * StringUtils.indexOfAny(*, 0, null)                  = -1
-     * StringUtils.indexOfAny(*, 0, [])                    = -1
-     * StringUtils.indexOfAny("zzabyycdxx", 0, ['z', 'a']) = 0
-     * StringUtils.indexOfAny("zzabyycdxx", 0, ['b', 'y']) = 3
-     * StringUtils.indexOfAny("aba", 0, ['z'])             = -1
-     * </pre>
-     *
-     * @param cs          the CharSequence to check, may be null.
-     * @param csStart Start searching the input {@code cs} at this index.
-     * @param searchChars the chars to search for, may be null.
-     * @return the index of any of the chars, -1 if no match or null input.
-     * @since 2.0
-     * @since 3.0 Changed signature from indexOfAny(String, char[]) to indexOfAny(CharSequence, char...)
-     */
-    public static int indexOfAny(final CharSequence cs, final int csStart, final char... searchChars) {
-        if (isEmpty(cs) || ArrayUtils.isEmpty(searchChars)) {
-            return INDEX_NOT_FOUND;
-        }
-        final int csLen = cs.length();
-        final int csLast = csLen - 1;
-        final int searchLen = searchChars.length;
-        final int searchLast = searchLen - 1;
-        for (int i = csStart; i < csLen; i++) {
-            final char ch = cs.charAt(i);
-            for (int j = 0; j < searchLen; j++) {
-                if (searchChars[j] == ch) {
-                    // ch is a supplementary character
-                    if (i >= csLast || j >= searchLast || !Character.isHighSurrogate(ch) || searchChars[j + 1] == cs.charAt(i + 1)) {
-                        return i;
-                    }
-                }
-            }
-        }
-        return INDEX_NOT_FOUND;
-    }
-
     /**
      * Find the first index of any of a set of potential substrings.
      *
@@ -2805,6 +2757,54 @@ public static int indexOfAny(final CharSequence str, final CharSequence... searc
         return ret == Integer.MAX_VALUE ? INDEX_NOT_FOUND : ret;
     }
 
+    /**
+     * Search a CharSequence to find the first index of any character in the given set of characters.
+     *
+     * <p>
+     * A {@code null} String will return {@code -1}. A {@code null} or zero length search array will return {@code -1}.
+     * </p>
+     * <p>
+     * The following is the same as {@code indexOfAny(cs, 0, searchChars)}.
+     * </p>
+     * <pre>
+     * StringUtils.indexOfAny(null, 0, *)                  = -1
+     * StringUtils.indexOfAny("", 0, *)                    = -1
+     * StringUtils.indexOfAny(*, 0, null)                  = -1
+     * StringUtils.indexOfAny(*, 0, [])                    = -1
+     * StringUtils.indexOfAny("zzabyycdxx", 0, ['z', 'a']) = 0
+     * StringUtils.indexOfAny("zzabyycdxx", 0, ['b', 'y']) = 3
+     * StringUtils.indexOfAny("aba", 0, ['z'])             = -1
+     * </pre>
+     *
+     * @param cs          the CharSequence to check, may be null.
+     * @param csStart Start searching the input {@code cs} at this index.
+     * @param searchChars the chars to search for, may be null.
+     * @return the index of any of the chars, -1 if no match or null input.
+     * @since 2.0
+     * @since 3.0 Changed signature from indexOfAny(String, char[]) to indexOfAny(CharSequence, char...)
+     */
+    public static int indexOfAny(final CharSequence cs, final int csStart, final char... searchChars) {
+        if (isEmpty(cs) || ArrayUtils.isEmpty(searchChars)) {
+            return INDEX_NOT_FOUND;
+        }
+        final int csLen = cs.length();
+        final int csLast = csLen - 1;
+        final int searchLen = searchChars.length;
+        final int searchLast = searchLen - 1;
+        for (int i = csStart; i < csLen; i++) {
+            final char ch = cs.charAt(i);
+            for (int j = 0; j < searchLen; j++) {
+                if (searchChars[j] == ch) {
+                    // ch is a supplementary character
+                    if (i >= csLast || j >= searchLast || !Character.isHighSurrogate(ch) || searchChars[j + 1] == cs.charAt(i + 1)) {
+                        return i;
+                    }
+                }
+            }
+        }
+        return INDEX_NOT_FOUND;
+    }
+
     /**
      * Search a CharSequence to find the first index of any character in the given set of characters.
      *
diff --git a/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java b/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java
index 85ca064a9..4fc29b0d7 100644
--- a/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java
+++ b/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java
@@ -95,30 +95,6 @@ private static int distance(final Class<?>[] fromClassArray, final Class<?>[] to
         return answer;
     }
 
-    /**
-     * Gets an accessible method (that is, one that can be invoked via reflection) with given name and parameters. If no such method can be found, return
-     * {@code null}. This is just a convenience wrapper for {@link #getAccessibleMethod(Method)}.
-     *
-     * @param cls            get method from this class.
-     * @param methodName     get method with this name.
-     * @param parameterTypes with these parameters types.
-     * @return The accessible method.
-     */
-    public static Method getAccessibleMethod(final Class<?> cls, final String methodName, final Class<?>... parameterTypes) {
-        return getAccessibleMethod(getMethodObject(cls, methodName, parameterTypes));
-    }
-
-    /**
-     * Gets an accessible method (that is, one that can be invoked via reflection) that implements the specified Method. If no such method can be found, return
-     * {@code null}.
-     *
-     * @param method The method that we wish to call, may be null.
-     * @return The accessible method
-     */
-    public static Method getAccessibleMethod(final Method method) {
-        return method != null ? getAccessibleMethod(method.getDeclaringClass(), method) : null;
-    }
-
     /**
      * Gets an accessible method (that is, one that can be invoked via reflection) that implements the specified Method. If no such method can be found, return
      * {@code null}.
@@ -144,6 +120,30 @@ public static Method getAccessibleMethod(final Class<?> cls, final Method method
         return method2 != null ? method2 : getAccessibleMethodFromSuperclass(cls, methodName, parameterTypes);
     }
 
+    /**
+     * Gets an accessible method (that is, one that can be invoked via reflection) with given name and parameters. If no such method can be found, return
+     * {@code null}. This is just a convenience wrapper for {@link #getAccessibleMethod(Method)}.
+     *
+     * @param cls            get method from this class.
+     * @param methodName     get method with this name.
+     * @param parameterTypes with these parameters types.
+     * @return The accessible method.
+     */
+    public static Method getAccessibleMethod(final Class<?> cls, final String methodName, final Class<?>... parameterTypes) {
+        return getAccessibleMethod(getMethodObject(cls, methodName, parameterTypes));
+    }
+
+    /**
+     * Gets an accessible method (that is, one that can be invoked via reflection) that implements the specified Method. If no such method can be found, return
+     * {@code null}.
+     *
+     * @param method The method that we wish to call, may be null.
+     * @return The accessible method
+     */
+    public static Method getAccessibleMethod(final Method method) {
+        return method != null ? getAccessibleMethod(method.getDeclaringClass(), method) : null;
+    }
+
     /**
      * Gets an accessible method (that is, one that can be invoked via
      * reflection) that implements the specified method, by scanning through


(commons-lang) 01/07: 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 d8aeb514ed993c7fefa17ecd0e2f490c39122422
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Wed Aug 20 16:41:55 2025 -0400

    Javadoc
---
 .../commons/lang3/concurrent/AbstractConcurrentInitializer.java  | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/apache/commons/lang3/concurrent/AbstractConcurrentInitializer.java b/src/main/java/org/apache/commons/lang3/concurrent/AbstractConcurrentInitializer.java
index 08f5d0545..57e4d915e 100644
--- a/src/main/java/org/apache/commons/lang3/concurrent/AbstractConcurrentInitializer.java
+++ b/src/main/java/org/apache/commons/lang3/concurrent/AbstractConcurrentInitializer.java
@@ -157,7 +157,7 @@ public void close() throws ConcurrentException {
     /**
      * Gets an Exception with a type of E as defined by a concrete subclass of this class.
      *
-     * @param e The actual exception that was thrown
+     * @param e The actual exception that was thrown.
      * @return a new exception with the actual type of E, that wraps e.
      */
     protected abstract E getTypedException(Exception e);
@@ -170,8 +170,8 @@ public void close() throws ConcurrentException {
      * Subclasses and clients that do not provide an initializer are expected to implement this method.
      * </p>
      *
-     * @return the managed data object
-     * @throws E if an error occurs during object creation
+     * @return the managed data object.
+     * @throws E if an error occurs during object creation.
      */
     @SuppressWarnings("unchecked")
     protected T initialize() throws E {
@@ -180,7 +180,6 @@ protected T initialize() throws E {
         } catch (final Exception e) {
             // Do this first so we don't pass a RuntimeException or Error into an exception constructor
             ExceptionUtils.throwUnchecked(e);
-
             // Depending on the subclass of AbstractConcurrentInitializer E can be Exception or ConcurrentException
             // if E is Exception the if statement below will always be true, and the new Exception object created
             // in getTypedException will never be thrown. If E is ConcurrentException and the if statement is false
@@ -198,7 +197,7 @@ protected T initialize() throws E {
      * call to initialize completes successfully. If the implementation of ConcurrentInitializer can initialize multiple objects, this will only return true if
      * all objects have been initialized.
      *
-     * @return true if all initialization is complete, otherwise false
+     * @return true if all initialization is complete, otherwise false.
      */
     protected abstract boolean isInitialized();