Fix broken implementation of ParTaskImpl::tasksFromIterable #347
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
tasksFromIterable
method inParTaskImpl
needs to read the contents of an iterator and then create an array of the read tasks. This is an unfortunate performance/memory tradeoff of using these two things: iterators don't have a length and arrays need one. The implementation reads the iterator's contents into a collection and then turns that collection into an array. The problem is, it then tries to cast that array ofObject
into a more narrow type, which is not allowed. This always results in a ClassCastException if the value is non null. The exists tests did not cover this case.The code has been fixed to take a less performant path and delegate the array creation to
tasksFromCollection
. A test has been written for theIterable
code path and verified through coverage analysis.This should fix #209 .
Before this change, if you use a class that implements
Iterable
but does not also implementCollection
withTask.par
then you'll be met with an exception:This is because the
Iterable
code path does some illegal casting ofObject[]
toTask[]
, which is not allowed.