com.esri.arcgisruntime.internal.util.UnmodifiableListImpl breaks the java.util.List contract

668
3
07-13-2021 02:35 AM
DaveWhitla
New Contributor III

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?

0 Kudos
3 Replies
DaveWhitla
New Contributor III

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
}
0 Kudos
DaveWhitla
New Contributor III

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.

DaveWhitla_0-1626189461810.png

 

DaveWhitla_0-1626188715649.png

 

0 Kudos
DaveWhitla
New Contributor III

Where can I log a bug?

0 Kudos