Skip to content

Conversation

@csrhodes
Copy link

It's possible for library code to define a Collection whose size property is one, but producing an iterator without any next element. This is probably some kind of mistake, but it's also very hard for a user of that library to deal with the error that toList() generates under those circumstances. If size is 1, conditionally generate an empty list if the initial iterator has no next element, consistently with other collection snapshotters.

It's possible for library code to define a Collection whose size
property is one, but producing an iterator without any next element.
This is probably some kind of mistake, but it's also very hard for a
user of that library to deal with the error that toList() generates
under those circumstances.  If size is 1, conditionally generate an
empty list if the initial iterator has no next element, consistently
with other collection snapshotters.
@csrhodes
Copy link
Author

This change is motivated by a user report of a problem in Android Studio, which calls toList() on the Gradle collection DefaultDomainObjectCollection. Relevant snippet of the stack trace:

Caused by: java.util.NoSuchElementException
	at org.gradle.api.internal.collections.AbstractIterationOrderRetainingElementSource$RealizedElementCollectionIterator.next(AbstractIterationOrderRetainingElementSource.java:290)
	at org.gradle.api.internal.DefaultDomainObjectCollection$IteratorImpl.next(DefaultDomainObjectCollection.java:494)
	at kotlin.collections.CollectionsKt___CollectionsKt.toList(_Collections.kt:1323)
	at com.android.ide.gradle.model.dependencies.DeclaredDependenciesModelBuilder.buildAll(DeclaredDependenciesModelBuilder.kt:46)
	at org.gradle.tooling.provider.model.internal.DefaultToolingModelBuilderRegistry$BuilderWithNoParameter.build(DefaultToolingModelBuilderRegistry.java:268)

Bug report at https://issuetracker.google.com/issues/460504494

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants