Skip to content

Commit 6622a46

Browse files
committed
Fix generics in org.apache.commons.lang3.stream.Streams.toArray(Class)
signature
1 parent 7bba7c5 commit 6622a46

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/changes/changes.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ The <action> type attribute can be add,update,fix,remove.
9292
<action issue="LANG-1773" type="fix" dev="ggregory" due-to="Éamonn McManus, Gary Gregory">Apache Commons Lang no longer builds on Android #1381.</action>
9393
<action issue="LANG-1772" type="fix" dev="ggregory" due-to="James Winters, Piotr P. Karwasz, Gary Gregory">Restrict size of cache to prevent overflow errors #1379.</action>
9494
<action issue="LANG-1772" type="fix" dev="ggregory" due-to="Gary Gregory">Reimplement org.apache.commons.lang3.ClassUtils.hierarchy(Class, Interfaces) using an AtomicReference.</action>
95-
<action type="fix" dev="ggregory" due-to="Ken Dombeck">Correct Javadoc code examples in DiffBuilder and ReflectionDiffBuilder #1400.</action>
95+
<action type="fix" dev="ggregory" due-to="Ken Dombeck">Fix Javadoc code examples in DiffBuilder and ReflectionDiffBuilder #1400.</action>
96+
<action type="fix" dev="ggregory" due-to="Gary Gregory">Fix generics in org.apache.commons.lang3.stream.Streams.toArray(Class) signature.</action>
9697
<!-- ADD -->
9798
<action type="add" dev="ggregory" due-to="Gary Gregory">Add Strings and refactor StringUtils.</action>
9899
<action issue="LANG-1747" type="add" dev="ggregory" due-to="Oliver B. Fischer, Gary Gregory">Add StopWatch.run([Failable]Runnable) and get([Failable]Supplier).</action>

src/main/java/org/apache/commons/lang3/stream/Streams.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ private static <T> Stream<T> streamOf(final T value) {
838838
* @param elementType Type of an element in the array.
839839
* @return a {@link Collector} which collects all the input elements into an array, in encounter order
840840
*/
841-
public static <T> Collector<T, ?, T[]> toArray(final Class<T> elementType) {
841+
public static <T> Collector<T, List<T>, T[]> toArray(final Class<T> elementType) {
842842
return new ArrayCollector<>(elementType);
843843
}
844844

src/test/java/org/apache/commons/lang3/stream/StreamsTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
package org.apache.commons.lang3.stream;
1818

19+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
1920
import static org.junit.jupiter.api.Assertions.assertEquals;
2021
import static org.junit.jupiter.api.Assertions.assertFalse;
2122
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -125,6 +126,16 @@ public Stream<DynamicTest> simpleStreamForEachFailing() {
125126
}));
126127
}
127128

129+
@Test
130+
void testArrayCollectorCombiner() {
131+
final String[] expected = { "A1", "B1" };
132+
assertArrayEquals(expected, Stream.of("A", "B").collect(Collectors.mapping(s -> s + "1", Streams.toArray(String.class))));
133+
assertArrayEquals(expected, Streams.failableStream("A", "B").collect(Collectors.mapping(s -> s + "1", Streams.toArray(String.class))));
134+
final List<String> left = new ArrayList<>();
135+
left.add("a");
136+
assertEquals(Arrays.asList("a", "b", "c"), Streams.toArray(String.class).combiner().apply(left, Arrays.asList("b", "c")));
137+
}
138+
128139
@SuppressWarnings("deprecation")
129140
@Test
130141
void testDeprefcatedCopnstructor() {

0 commit comments

Comments
 (0)