Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@adamgfraser
Copy link
Contributor

Resolves #3852.

The specialized version of toArray for a Chunk backed by an Array was just upcasting the underlying array and returning it, which is both not safe and exposes the underlying mutable array to the caller, potentially allowing the caller to mutate the array and violating the referential transparency of Chunk.

This PR deletes the specialized version. The version defined on the parent class just creates a new array and then calls toArray to copy all of the elements to the new array, which is implemented very efficiency for an array chunk in terms of Array.copy.

@adamgfraser adamgfraser requested review from iravid and jdegoes June 22, 2020 14:32
@adamgfraser adamgfraser merged commit 4c20c4f into zio:master Jun 27, 2020
@adamgfraser adamgfraser deleted the toarray branch June 27, 2020 01:24
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.

Chunk.toArray throws ClassCastException

2 participants