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 2021/12/04 15:07:33 UTC

[commons-lang] branch master updated (69941d9 -> 45d454b)

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 69941d9  Fix PMD: Avoid using a branching statement as the last in a loop.
     new bf48d8a  Javadoc typos.
     new 49cfcc2  Better param names.
     new 45d454b  Fix NullPointerException in ThreadUtils.getSystemThreadGroup() when the current thread is stopped.

The 3 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/ThreadUtils.java | 49 ++++++++++++----------
 2 files changed, 27 insertions(+), 23 deletions(-)

[commons-lang] 01/03: Javadoc typos.

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 bf48d8a53cc6f4e702412dd864a8741f2a06ea36
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Dec 4 09:58:57 2021 -0500

    Javadoc typos.
---
 .../java/org/apache/commons/lang3/ThreadUtils.java   | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/main/java/org/apache/commons/lang3/ThreadUtils.java b/src/main/java/org/apache/commons/lang3/ThreadUtils.java
index 3b53a5c..15b13a4 100644
--- a/src/main/java/org/apache/commons/lang3/ThreadUtils.java
+++ b/src/main/java/org/apache/commons/lang3/ThreadUtils.java
@@ -58,7 +58,7 @@ public class ThreadUtils {
     }
 
     /**
-     * A predicate implementation which matches a thread or threadgroup name.
+     * A predicate implementation which matches a thread or thread group name.
      */
     public static class NamePredicate implements ThreadPredicate, ThreadGroupPredicate {
 
@@ -67,7 +67,7 @@ public class ThreadUtils {
         /**
          * Predicate constructor
          *
-         * @param name thread or threadgroup name
+         * @param name thread or thread group name
          * @throws IllegalArgumentException if the name is {@code null}
          */
         public NamePredicate(final String name) {
@@ -87,15 +87,15 @@ public class ThreadUtils {
     }
 
     /**
-     * A predicate for selecting threadgroups.
+     * A predicate for selecting thread groups.
      */
     // When breaking BC, replace this with Predicate<ThreadGroup>
     @FunctionalInterface
     public interface ThreadGroupPredicate {
 
         /**
-         * Evaluates this predicate on the given threadgroup.
-         * @param threadGroup the threadgroup
+         * Evaluates this predicate on the given thread group.
+         * @param threadGroup the thread group
          * @return {@code true} if the threadGroup matches the predicate, otherwise {@code false}
          */
         boolean test(ThreadGroup threadGroup);
@@ -211,12 +211,12 @@ public class ThreadUtils {
     }
 
     /**
-     * Select all active threadgroups which match the given predicate and which is a subgroup of the given thread group (or one of its subgroups).
+     * Select all active thread groups which match the given predicate and which is a subgroup of the given thread group (or one of its subgroups).
      *
      * @param group the thread group
-     * @param recurse if {@code true} then evaluate the predicate recursively on all threadgroups in all subgroups of the given group
+     * @param recurse if {@code true} then evaluate the predicate recursively on all thread groups in all subgroups of the given group
      * @param predicate the predicate
-     * @return An unmodifiable {@code Collection} of active threadgroups which match the given predicate and which is a subgroup of the given thread group
+     * @return An unmodifiable {@code Collection} of active thread groups which match the given predicate and which is a subgroup of the given thread group
      * @throws IllegalArgumentException if the given group or predicate is null
      * @throws  SecurityException  if the current thread cannot modify
      *          thread groups from this thread's thread group up to the system thread group
@@ -243,10 +243,10 @@ public class ThreadUtils {
     }
 
     /**
-     * Select all active threadgroups which match the given predicate.
+     * Select all active thread groups which match the given predicate.
      *
      * @param predicate the predicate
-     * @return An unmodifiable {@code Collection} of active threadgroups matching the given predicate
+     * @return An unmodifiable {@code Collection} of active thread groups matching the given predicate
      * @throws IllegalArgumentException if the predicate is null
      * @throws  SecurityException
      *          if the current thread cannot access the system thread group

[commons-lang] 02/03: Better param names.

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 49cfcc2c479e606bfb9b1b26f50b63397222d965
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Dec 4 10:02:28 2021 -0500

    Better param names.
---
 .../java/org/apache/commons/lang3/ThreadUtils.java   | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/main/java/org/apache/commons/lang3/ThreadUtils.java b/src/main/java/org/apache/commons/lang3/ThreadUtils.java
index 15b13a4..db9c6c6 100644
--- a/src/main/java/org/apache/commons/lang3/ThreadUtils.java
+++ b/src/main/java/org/apache/commons/lang3/ThreadUtils.java
@@ -213,7 +213,7 @@ public class ThreadUtils {
     /**
      * Select all active thread groups which match the given predicate and which is a subgroup of the given thread group (or one of its subgroups).
      *
-     * @param group the thread group
+     * @param threadGroup the thread group
      * @param recurse if {@code true} then evaluate the predicate recursively on all thread groups in all subgroups of the given group
      * @param predicate the predicate
      * @return An unmodifiable {@code Collection} of active thread groups which match the given predicate and which is a subgroup of the given thread group
@@ -221,15 +221,15 @@ public class ThreadUtils {
      * @throws  SecurityException  if the current thread cannot modify
      *          thread groups from this thread's thread group up to the system thread group
      */
-    public static Collection<ThreadGroup> findThreadGroups(final ThreadGroup group, final boolean recurse, final ThreadGroupPredicate predicate) {
-        Validate.notNull(group, "group");
+    public static Collection<ThreadGroup> findThreadGroups(final ThreadGroup threadGroup, final boolean recurse, final ThreadGroupPredicate predicate) {
+        Validate.notNull(threadGroup, "group");
         Validate.notNull(predicate, "predicate");
 
-        int count = group.activeGroupCount();
+        int count = threadGroup.activeGroupCount();
         ThreadGroup[] threadGroups;
         do {
             threadGroups = new ThreadGroup[count + (count / 2) + 1]; //slightly grow the array size
-            count = group.enumerate(threadGroups, recurse);
+            count = threadGroup.enumerate(threadGroups, recurse);
             //return value of enumerate() must be strictly less than the array size according to javadoc
         } while (count >= threadGroups.length);
 
@@ -276,7 +276,7 @@ public class ThreadUtils {
     /**
      * Select all active threads which match the given predicate and which belongs to the given thread group (or one of its subgroups).
      *
-     * @param group the thread group
+     * @param threadGroup the thread group
      * @param recurse if {@code true} then evaluate the predicate recursively on all threads in all subgroups of the given group
      * @param predicate the predicate
      * @return An unmodifiable {@code Collection} of active threads which match the given predicate and which belongs to the given thread group
@@ -284,15 +284,15 @@ public class ThreadUtils {
      * @throws  SecurityException  if the current thread cannot modify
      *          thread groups from this thread's thread group up to the system thread group
      */
-    public static Collection<Thread> findThreads(final ThreadGroup group, final boolean recurse, final ThreadPredicate predicate) {
-        Validate.notNull(group, "The group must not be null");
+    public static Collection<Thread> findThreads(final ThreadGroup threadGroup, final boolean recurse, final ThreadPredicate predicate) {
+        Validate.notNull(threadGroup, "The group must not be null");
         Validate.notNull(predicate, "The predicate must not be null");
 
-        int count = group.activeCount();
+        int count = threadGroup.activeCount();
         Thread[] threads;
         do {
             threads = new Thread[count + (count / 2) + 1]; //slightly grow the array size
-            count = group.enumerate(threads, recurse);
+            count = threadGroup.enumerate(threads, recurse);
             //return value of enumerate() must be strictly less than the array size according to javadoc
         } while (count >= threads.length);
 

[commons-lang] 03/03: Fix NullPointerException in ThreadUtils.getSystemThreadGroup() when the current thread is stopped.

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 45d454b3e7aeccfadf855dda8bdfca93d90fef0c
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Dec 4 10:07:30 2021 -0500

    Fix NullPointerException in ThreadUtils.getSystemThreadGroup() when the
    current thread is stopped.
---
 src/changes/changes.xml                                 | 1 +
 src/main/java/org/apache/commons/lang3/ThreadUtils.java | 9 ++++++---
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index de2be06..5a50f59 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="fix" dev="ggregory" due-to="Arturo Bernal">Use final and Remove redundant String. #813, #816.</action>
     <action                   type="fix" dev="ggregory" due-to="CiprianBodnarescu">Use Set instead of List for checking the contains() method #734.</action>
     <action                   type="fix" dev="kinow" due-to="Roland Kreuzer">Javadoc for StringUtils.substringBefore(String str, int separator) doesn't mention that the separator is an int.</action>
+    <action                   type="fix" dev="ggregory" due-to="Gary Gregory">Fix NullPointerException in ThreadUtils.getSystemThreadGroup() when the current thread is stopped.</action>
     <!-- ADD -->
     <action                   type="add" dev="ggregory" due-to="Gary Gregory">Add EnumUtils.getEnumSystemProperty(...).</action>
     <action                   type="add" dev="ggregory" due-to="Gary Gregory">Add TriConsumer.</action>
diff --git a/src/main/java/org/apache/commons/lang3/ThreadUtils.java b/src/main/java/org/apache/commons/lang3/ThreadUtils.java
index db9c6c6..f8b8587 100644
--- a/src/main/java/org/apache/commons/lang3/ThreadUtils.java
+++ b/src/main/java/org/apache/commons/lang3/ThreadUtils.java
@@ -417,14 +417,17 @@ public class ThreadUtils {
 
     /**
      * Gets the system thread group (sometimes also referred as "root thread group").
+     * <p>
+     * This method returns null if this thread has died (been stopped).
+     * </p>
      *
      * @return the system thread group
-     * @throws  SecurityException  if the current thread cannot modify
-     *          thread groups from this thread's thread group up to the system thread group
+     * @throws SecurityException if the current thread cannot modify thread groups from this thread's thread group up to the
+     *         system thread group
      */
     public static ThreadGroup getSystemThreadGroup() {
         ThreadGroup threadGroup = Thread.currentThread().getThreadGroup();
-        while (threadGroup.getParent() != null) {
+        while (threadGroup != null && threadGroup.getParent() != null) {
             threadGroup = threadGroup.getParent();
         }
         return threadGroup;