Inspectopedia Help

Broken Iterator

Broken Iterator

For LinkedHashMap:

The spliterators returned by LinkedHashMap in Android Nougat (API levels 24 and 25) use the wrong order (inconsistent with the iterators, which use the correct order), despite reporting Spliterator.ORDERED. You may use the following code fragments to obtain a correctly ordered Spliterator on API level 24 and 25:

For a Collection view c = lhm.entrySet(), c = lhm.keySet() or c = lhm.values(), use java.util.Spliterators.spliterator(c, c.spliterator().characteristics()) instead of c.spliterator().

Instead of c.stream() or c.parallelStream(), use java.util.stream.StreamSupport.stream(spliterator, false) to construct a (nonparallel) Stream from such a Spliterator.

For Vector:

The listIterator() returned for a Vector has a broken add() implementation on Android N (API level 24). Consider switching to ArrayList and if necessary adding synchronization.

Issue id: BrokenIterator

https://developer.android.com/reference/java/util/LinkedHashMap

Inspection Details

Available in:

IntelliJ IDEA 2023.3, Qodana for Android 2023.3, Qodana for JVM 2023.3

Plugin:

Android, 2022.3.1 Beta 2

Last modified: 13 July 2023