Skip to content

Lists::transform and probably others do not produce spliterators/iterators with correct characteristics #8165

@xxDark

Description

@xxDark

Guava Version

33.5.0-jre

Description

If a collection produces a spliterator with special behavior, Guava's collection views may not pick up that implementation.

Example

import com.google.common.collect.Lists;

import java.util.concurrent.CopyOnWriteArrayList;

public class Test {

	static void main() {
		var cow = new CopyOnWriteArrayList<Integer>();
		Thread.ofPlatform().daemon().start(() -> {
			do {
				for (int i = 0; i < 100_000; i++) {
					cow.add(i);
				}
				cow.clear();
			} while (true);
		});
		var view = Lists.transform(cow, s -> s);
		do {
			view.stream().forEach(integer -> {});
		} while (true);
	}
}

Expected Behavior

Program keeps running.

Actual Behavior

Exception in thread "main" java.util.ConcurrentModificationException
	at java.base/java.util.AbstractList$RandomAccessSpliterator.get(AbstractList.java:739)
	at java.base/java.util.AbstractList$RandomAccessSpliterator.forEachRemaining(AbstractList.java:722)
	at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:803)
	at Test.main(Test.java:19)

Packages

com.google.common.collect

Platforms

Java 21

Checklist

  • I agree to follow the code of conduct.

  • I can reproduce the bug with the latest version of Guava available.

Metadata

Metadata

Assignees

Labels

P3no SLOtype=defectBug, not working as expected

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions