Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Java 9 Stream APIs #9837

Merged
merged 19 commits into from
Nov 10, 2023
Merged

Conversation

niloc132
Copy link
Contributor

Partial #9547

@niloc132
Copy link
Contributor Author

https://github.com/niloc132/gwt/actions/runs/5315644262/jobs/9624263435 shows successful build in all three tested Java runtime versions.

@niloc132
Copy link
Contributor Author

niloc132 commented Nov 8, 2023

@zbynek so it seems that Java8 has the same bug that GWT had here previously, so my new test above is failing in legacy dev mode.

import java.util.stream.DoubleStream;
import java.util.Arrays;

class Test {
        public static void main(String[] args) {
                int[] callCount = { 0 };
                double[] values = DoubleStream.iterate(0, val -> {
                        callCount[0]++;
                        return val + 1;
                }).limit(5).toArray();
                
                System.out.println(callCount[0]);
                System.out.println(Arrays.toString(values));
        }
}

In Java 11+, this results in

4
[0.0, 1.0, 2.0, 3.0, 4.0]

But in Java 8 (both my local copy and the build that the GHA runner is using), this yields:

5
[0.0, 1.0, 2.0, 3.0, 4.0]

Excitingly, Java 8 only has this bug for IntStream, DoubleStream, and LongStream, just plain Stream has the same behavior in 8 and 11/17:

import java.util.stream.Stream;
import java.util.Arrays;

class Test {
        public static void main(String[] args) {
                int[] callCount = { 0 };
                Integer[] values = Stream.iterate(0, val -> {
                        callCount[0]++;
                        return val + 1;
                }).limit(5).toArray(Integer[]::new);
                
                System.out.println(callCount[0]);
                System.out.println(Arrays.toString(values));
        }
}
4
[0, 1, 2, 3, 4]

Note that these would pass in legacy dev mode in Java 11/17, but we
don't run legacy dev mode tests for those JVMs for a variety of reasons.
@niloc132
Copy link
Contributor Author

niloc132 commented Nov 8, 2023

@niloc132 niloc132 requested a review from zbynek November 8, 2023 12:41
@niloc132 niloc132 merged commit 1ca97c4 into gwtproject:main Nov 10, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants