RFR: 8318420 : AbstractPipeline invokes overridden method in constructor

Viktor Klang vklang at openjdk.org
Thu Oct 19 09:31:10 UTC 2023


This PR corrects so that `opIsStateful()` is not invoked as a part of the java.util.stream.AbstractPipeline constructor—as `opIsStateful()` is intended to be overridden by subclasses, and as their own constructors have not run when their superclass constructor runs, this means that `opIsStateful()` cannot base its return value on any class members of the subclass.

Since `opIsStateful()` is only needed for parallel streams, we can therefor defer the invocation of `opIsStateful()` until evaluation-time, and as such we can remove the need for having an instance field to store the result of the invocation—making Stream instances potentially a tiny bit smaller, reducing Stream-construction overhead, while still preserving semantics.

-------------

Commit messages:
 - Avoids calling opIsStateful() during AbstractPipeline constructor

Changes: https://git.openjdk.org/jdk/pull/16239/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=16239&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8318420
  Stats: 24 lines in 1 file changed: 15 ins; 8 del; 1 mod
  Patch: https://git.openjdk.org/jdk/pull/16239.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/16239/head:pull/16239

PR: https://git.openjdk.org/jdk/pull/16239


More information about the core-libs-dev mailing list