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 <[email protected]> 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;
