Skip to content

Commit

Permalink
8318420: AbstractPipeline invokes overridden method in constructor
Browse files Browse the repository at this point in the history
Reviewed-by: psandoz
  • Loading branch information
Viktor Klang authored and Paul Sandoz committed Oct 20, 2023
1 parent 5281499 commit 200b5a2
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/java.base/share/classes/java/util/stream/AbstractPipeline.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,6 @@ abstract class AbstractPipeline<E_IN, E_OUT, S extends BaseStream<E_OUT, S>>
*/
private boolean linkedOrConsumed;

/**
* True if there are any stateful ops in the pipeline; only valid for the
* source stage.
*/
private boolean sourceAnyStateful;

private Runnable sourceCloseAction;

/**
Expand Down Expand Up @@ -208,8 +202,6 @@ abstract class AbstractPipeline<E_IN, E_OUT, S extends BaseStream<E_OUT, S>>
this.sourceOrOpFlags = opFlags & StreamOpFlag.OP_MASK;
this.combinedFlags = StreamOpFlag.combineOpFlags(opFlags, previousStage.combinedFlags);
this.sourceStage = previousStage.sourceStage;
if (opIsStateful())
sourceStage.sourceAnyStateful = true;
this.depth = previousStage.depth + 1;
}

Expand Down Expand Up @@ -386,6 +378,21 @@ final int getStreamFlags() {
return StreamOpFlag.toStreamFlags(combinedFlags);
}

/**
* Returns whether any of the stages of the current segment is stateful
* or not.
* @return {@code true} if any stage in this segment is stateful,
* {@code false} if not.
*/
protected final boolean hasAnyStateful() {
var result = false;
for (var u = sourceStage.nextStage;
u != null && !(result = u.opIsStateful()) && u != this;
u = u.nextStage) {
}
return result;
}

/**
* Get the source spliterator for this pipeline stage. For a sequential or
* stateless parallel pipeline, this is the source spliterator. For a
Expand All @@ -409,7 +416,7 @@ else if (sourceStage.sourceSupplier != null) {
throw new IllegalStateException(MSG_CONSUMED);
}

if (isParallel() && sourceStage.sourceAnyStateful) {
if (isParallel() && hasAnyStateful()) {
// Adapt the source spliterator, evaluating each stateful op
// in the pipeline up to and including this pipeline stage.
// The depth and flags of each pipeline stage are adjusted accordingly.
Expand Down

1 comment on commit 200b5a2

@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.