Given the following (which attempts to provide enough context without irrelevant detail) ...
var featureCollection = new FeatureCollection();
var table = new FeatureCollectionTable(getFields(), getGeometryType(), getSpatialReference());
var featureCollectionLayer = new FeatureCollectionLayer(featureCollection);
featureCollection.getTables().add(table);
A little later in execution ...
featureCollectionLayer.getLayers().size()
returns 1
while
featureCollectionLayer.getLayers().get(0)
throws NoSuchElementException("java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0")
and even afterwards
featureCollectionLayer.getLayers().listIterator().hasNext()
returns true
while
featureCollectionLayer.getLayers().listIterator().next()
throws NoSuchElementException("java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0")
What gives?
My first post above didn't really spell it out clearly enough.
The following code fails (sometimes) inside the if block
var iterator = featureCollectionLayer.getLayers().iterator();
if (iterator.hasNext()) {
iterator.next(); // <-- IndexOutOfBoundsException here
}
The cause would appear to be that size() returns (int)this.mCoreArray.getSize() while get(int) indexes this.mElementCache, which at the time has size == 0 because mCoreArray was empty when the UnmodifiableListImpl was constructed.
While UnmodifiableListImpl is an unmodifiable wrapper, the CoreArray it adapts is evidently mutable. Nothing wrong with that - its just that the assumption encoded in get(int) is invalid.
Where can I log a bug?