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

The result types in sumOfPrimitiveProcedure.stg need to be widened to prevent overflow #1453

Open
donraab opened this issue Apr 12, 2023 · 5 comments
Assignees

Comments

@donraab
Copy link
Contributor

donraab commented Apr 12, 2023

I discovered there is an overflow error using sumOfInt in the following code when the batch size exceeded 536

This code returned the correct sum:

long sum = Interval.oneTo(2_000_000)
        .toList()
        .asParallel(Executors.newSingleThreadExecutor(), 536)
        .sumOfInt(each -> each * 2);

This code returned the incorrect sum:

long sum = Interval.oneTo(2_000_000)
        .toList()
        .asParallel(Executors.newSingleThreadExecutor(), 537)
        .sumOfInt(each -> each * 2);

I tracked the problem down to SumOfIntProcedure returning int instead of long for the result. This Procedure must be used in the individual batches and if a batch gets large enough with large values being summed, overflow is occurring.

https://github.com/eclipse/eclipse-collections/blob/master/eclipse-collections-code-generator/src/main/resources/impl/block/procedure/sumOfPrimitiveProcedure.stg#L33

@donraab donraab assigned motlin and unassigned motlin Apr 12, 2023
@rzrobin213
Copy link
Contributor

Hi, I would like to take up this issue. Could you assign it to me? Thank you!

@donraab
Copy link
Contributor Author

donraab commented Apr 12, 2023

Thanks for volunteering @rzrobin213 ! I have assigned the issue to you.

@TheJavaGuy
Copy link
Contributor

@donraab File eclipse-collections/src/main/java/org/eclipse/collections/impl/block/procedure/SumOfIntProcedure.java seems not to be auto-generated. OTOH, file eclipse-collections/target/generated-sources/java/org/eclipse/collections/impl/block/procedure/SumOfByteProcedure.java says that it is generated from the sumOfPrimitiveProcedure.stg.

@lightgrey7
Copy link

Hi! Could you assign this issue to me, since rzrobin123 do not seem to be working on this.

lightgrey7 added a commit to lightgrey7/eclipse-collections that referenced this issue Dec 1, 2023
@lightgrey7
Copy link

hello!! I have made a pull request regarding this issue..please review it.
@donraab

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

No branches or pull requests

5 participants