WFS GetFeature request with a propertyname parameter fails when layer attributes are customized (removed or reordered)
Description
Steps to reproduce:
Start GeoServer with demo data, for example using docker run -it --rm -p 8080:8080 docker.osgeo.org/geoserver:2.25.3
Get URL http://localhost:8080/geoserver/ne/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=ne%3Acountries&maxFeatures=50&outputFormat=text%2Fcsv&propertyname=NAME, this succeeds
Edit the ne:countries layer, check “Customize attributes”, remove any attribute other than NAME
Do the request in step 2) again, this fails with: java.lang.ArrayIndexOutOfBoundsException: Index 18 out of bounds for length 1
The same request but with outputFormat=application%2Fjson returns features with attributes not requested but with all null values except the requested NAME attribute.
Reordering the customized attributes instead of removing an attribute also throws a similar exception.
I think the problem cause might be that the schema of the feature type is modified according to the customizations and the requested propertynames, but the features in the FeatureCollection seem to be created without the customizations.
In CSVOutputFormat a formatters array is created using FeatureCollection.getSchema().getAttributeCount() but in CSVOutputFormat.write() this array is indexed with a loop from 0 to SimpleFeature.getAttributeCount().
GeoServer log output:
I’ve also seen a stacktrace similar to , see below. So this might be related:
Steps to reproduce:
Start GeoServer with demo data, for example using
docker run -it --rm -p 8080:8080 docker.osgeo.org/geoserver:2.25.3
Get URL
http://localhost:8080/geoserver/ne/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=ne%3Acountries&maxFeatures=50&outputFormat=text%2Fcsv&propertyname=NAME
, this succeedsEdit the
ne:countries
layer, check “Customize attributes”, remove any attribute other thanNAME
Do the request in step 2) again, this fails with:
java.lang.ArrayIndexOutOfBoundsException: Index 18 out of bounds for length 1
The same request but with
outputFormat=application%2Fjson
returns features with attributes not requested but with all null values except the requested NAME attribute.Reordering the customized attributes instead of removing an attribute also throws a similar exception.
I think the problem cause might be that the schema of the feature type is modified according to the customizations and the requested propertynames, but the features in the FeatureCollection seem to be created without the customizations.
In CSVOutputFormat a
formatters
array is created usingFeatureCollection.getSchema().getAttributeCount()
but in CSVOutputFormat.write() this array is indexed with a loop from 0 toSimpleFeature.getAttributeCount()
.GeoServer log output:
I’ve also seen a stacktrace similar to , see below. So this might be related: