8048691: Spliterator.SORTED characteristics gets cleared for BaseStream.spliterator
Reviewed-by: psandoz, alanb
This commit is contained in:
parent
8d78e8cadc
commit
f12ed061ae
src/java.base/share/classes/java/util/stream
test/jdk/java/util/stream/test/org/openjdk/tests/java/util/stream
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -248,6 +248,11 @@ class StreamSpliterators {
|
||||
c |= (spliterator.characteristics() & (Spliterator.SIZED | Spliterator.SUBSIZED));
|
||||
}
|
||||
|
||||
// It's not allowed for a Spliterator to report SORTED if not also ORDERED
|
||||
if ((c & Spliterator.SORTED) != 0 && (c & Spliterator.ORDERED) == 0) {
|
||||
c &= ~(Spliterator.SORTED);
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -605,6 +605,27 @@ public class StreamSpliteratorTest extends OpTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCharacteristicsForSortedUnorderedStreamSpliterators() {
|
||||
assertValidCombinationOfSortedAndOrdered(
|
||||
DoubleStream.of(3d,2d,4d,1d,5d).sorted().unordered().spliterator()
|
||||
);
|
||||
assertValidCombinationOfSortedAndOrdered(
|
||||
IntStream.of(3,2,4,1,5).sorted().unordered().spliterator()
|
||||
);
|
||||
assertValidCombinationOfSortedAndOrdered(
|
||||
LongStream.of(3L,2L,4L,1L,5L).sorted().unordered().spliterator()
|
||||
);
|
||||
assertValidCombinationOfSortedAndOrdered(
|
||||
Stream.of(3,2,4,1,5).sorted().unordered().spliterator()
|
||||
);
|
||||
}
|
||||
|
||||
void assertValidCombinationOfSortedAndOrdered(Spliterator<?> s) {
|
||||
if (s.hasCharacteristics(Spliterator.SORTED))
|
||||
Assert.assertTrue(s.hasCharacteristics(Spliterator.ORDERED));
|
||||
}
|
||||
|
||||
private List<Function<DoubleStream, DoubleStream>> doubleStreamFunctions;
|
||||
|
||||
List<Function<DoubleStream, DoubleStream>> doubleStreamFunctions() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user