WFS GetFeature request with a propertyname parameter fails when layer attributes are customized (removed or reordered)

Description

Steps to reproduce:

  1. Start GeoServer with demo data, for example using docker run -it --rm -p 8080:8080 docker.osgeo.org/geoserver:2.25.3

  2. 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

  3. Edit the ne:countries layer, check “Customize attributes”, remove any attribute other than NAME

  4. 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:

Environment

Any

Activity

Mark Prins December 16, 2024 at 9:03 PM

A fix was merged in GeoTools for 33.0/32.2/31.5, so this should be fixed in related GeoServer versions, an integration test was merged into GeoServer

Matthijs Laan August 9, 2024 at 1:50 PM

Seems to work fine with shapefile layers. I also got the error with a PostGIS store.

Fixed

Details

Assignee

Reporter

Fix versions

Components

Priority

Created August 9, 2024 at 1:15 PM
Updated December 16, 2024 at 9:40 PM
Resolved December 16, 2024 at 9:05 PM