mirror of
https://github.com/apache/commons-lang.git
synced 2025-02-08 11:05:09 +00:00
[LANG-1706] ThreadUtils find methods should not return null items #1098
This commit is contained in:
parent
c94c3a0be5
commit
e6796a0ec6
@ -54,6 +54,7 @@ The <action> type attribute can be add,update,fix,remove.
|
||||
<action issue="LANG-1704" type="fix" dev="ggregory" due-to="Sung Ho Yoon">[Javadoc] Fix Incorrect Description in Processor isAarch64() #1093.</action>
|
||||
<action type="fix" dev="ggregory" due-to="ljacqu">[Javadoc] Point to right getShortClassName flavor in Javadoc for relevant notes #1097.</action>
|
||||
<action type="fix" dev="ggregory" due-to="hduelme">Improve performance of StringUtils.isMixedCase() #1096.</action>
|
||||
<action issue="LANG-1706" type="fix" dev="ggregory" due-to="Alberto Fernández">ThreadUtils find methods should not return null items #1098.</action>
|
||||
<!-- ADD -->
|
||||
<action type="add" dev="ggregory" due-to="Rob Spoor, Gary Gregory">Add Functions#function(Function).</action>
|
||||
<action type="add" dev="ggregory" due-to="Rob Spoor, Gary Gregory">Add FailableFunction#function(FailableFunction).</action>
|
||||
|
@ -284,7 +284,7 @@ public static Collection<ThreadGroup> findThreadGroups(final ThreadGroup threadG
|
||||
count = threadGroup.enumerate(threadGroups, recurse);
|
||||
//return value of enumerate() must be strictly less than the array size according to Javadoc
|
||||
} while (count >= threadGroups.length);
|
||||
return Collections.unmodifiableCollection(Stream.of(threadGroups).filter(predicate).collect(Collectors.toList()));
|
||||
return Collections.unmodifiableCollection(Stream.of(threadGroups).limit(count).filter(predicate).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -376,7 +376,7 @@ public static Collection<Thread> findThreads(final ThreadGroup threadGroup, fina
|
||||
count = threadGroup.enumerate(threads, recurse);
|
||||
//return value of enumerate() must be strictly less than the array size according to javadoc
|
||||
} while (count >= threads.length);
|
||||
return Collections.unmodifiableCollection(Stream.of(threads).filter(predicate).collect(Collectors.toList()));
|
||||
return Collections.unmodifiableCollection(Stream.of(threads).limit(count).filter(predicate).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -31,7 +31,9 @@
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.time.Duration;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@ -148,6 +150,20 @@ public void testConstructor() {
|
||||
assertFalse(Modifier.isFinal(ThreadUtils.class.getModifiers()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllThreadGroupsDoesNotReturnNull() {
|
||||
// LANG-1706 getAllThreadGroups and findThreadGroups should not return null items
|
||||
Collection<ThreadGroup> threads = ThreadUtils.getAllThreadGroups();
|
||||
assertEquals(0, threads.stream().filter(Objects::isNull).count());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllThreadsDoesNotReturnNull() {
|
||||
// LANG-1706 getAllThreads and findThreads should not return null items
|
||||
Collection<Thread> threads = ThreadUtils.getAllThreads();
|
||||
assertEquals(0, threads.stream().filter(Objects::isNull).count());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidThreadId() {
|
||||
assertThrows(IllegalArgumentException.class, () -> ThreadUtils.findThreadById(-5L));
|
||||
@ -390,4 +406,5 @@ public void testThreadsSameName() throws InterruptedException {
|
||||
alsot1.join();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user