Skip to content

Commit

Permalink
8048691: Spliterator.SORTED characteristics gets cleared for BaseStre…
Browse files Browse the repository at this point in the history
…am.spliterator

Reviewed-by: psandoz, alanb
  • Loading branch information
Viktor Klang committed May 7, 2024
1 parent 8d78e8c commit f12ed06
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -248,6 +248,11 @@ public final int characteristics() {
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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -605,6 +605,27 @@ public void testDoubleParSpliterators(String name, TestData.OfDouble data) {
}
}

@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() {
Expand Down

1 comment on commit f12ed06

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.