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?