You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Stefan Pfafferott (Jira)" <ji...@apache.org> on 2023/10/09 11:32:00 UTC

[jira] [Created] (LANG-1715) ThreadUtils.getAllThreads returns null threads

Stefan Pfafferott created LANG-1715:
---------------------------------------

             Summary: ThreadUtils.getAllThreads returns null threads
                 Key: LANG-1715
                 URL: https://issues.apache.org/jira/browse/LANG-1715
             Project: Commons Lang
          Issue Type: Bug
          Components: lang.*
    Affects Versions: 3.13.0
            Reporter: Stefan Pfafferott


The Collection returned by ThreadUtils.getAllThreads() contains null elements.

Example test code:
{code:java}
@Test
public void getAllThreads() {
    Collection<Thread> allThreads = ThreadUtils.getAllThreads();
    allThreads.forEach(Assertions::assertNotNull);
}
{code}
Cause should be in ThreadUtils.findThreads line 375 in conjunction with line 379. The array is created larger than the actual number of threads. getAllThreads uses an "always true" predicate. This way, the null elements of the array are copied to the result list.

In 3.12.0, only the elements up to the returned "count" are copied.

I suggest to add a "not null" filter when creating the result list.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)