ArrayIndexOutOfBoundsException In GMLComplexTypes

Description

In org.geotools.xml.handlers.ComplexElementHandler is code like this:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 if (elements == null) { if (type != null) { ElementValue[] vals; if(type.isMixed()){ vals = new ElementValue[1]; vals[0] = new DefaultElementValue(null, text); // null is ok as // this represents the mixed content }else{ vals = new ElementValue[0]; } value = type.getValue(elem, vals, attr, hints); } else { value = text; } return; }

Which will set

1 vals = new ElementValue[0];

in some cases.

The class org.geotools.xml.gml.GMLComplexTypes.MultiPointType
has a method

1 2 3 public Object getValue(Element element, ElementValue[] value, Attributes attrs, Map hints) throws SAXException, OperationNotSupportedException { Element e = value[0].getElement();

Which will always result in an ArrayIndexOutOfBoundsException in this case (Because the array is emtpy and has no [0] element).

Some Implementations of Type like org.geotools.xml.gml.GMLComplexTypes.PointMemberType in this class have a check for this:

1 2 3 4 5 6 7 8 9 10 public Object getValue(Element element, ElementValue[] value, Attributes attrs, Map hints) throws SAXException { if ((value == null) || (value.length == 0) || (value[0] == null)) { return null; // do nothing ... this is allowed } if (value.length > 1) { throw new SAXException("Cannot have more than one geom per " + getName()); }

If the ArrayIndexOutOfBoundsException occurs the follwing catch will happen in FeatureReaderItertator:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 public boolean hasNext() { try { if (reader == null) return false; if (reader.hasNext()) { return true; } else { // auto close because we don't trust // client code to call closed :-) close(); return false; } } catch (Exception e) { close(); return false; // failure sounds like lack of next to me } }

and parsing of the features will end abruptly (and silently!).

Example GML:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 <gml:featureMember> <SCHEMA:TEST fid="TEST.fid--78937a77_15085ea8137_-1b93"> <SCHEMA:ID>529</SCHEMA:ID> <SCHEMA:bezeichnung>Gruppe NÖ Nord</SCHEMA:bezeichnung> <SCHEMA:typ>TYP</SCHEMA:typ> <SCHEMA:typ_lang>LANG</SCHEMA:typ_lang> <SCHEMA:rt>Z00</SCHEMA:rt> <SCHEMA:von>35.0000</SCHEMA:von> <SCHEMA:bis>44.5170</SCHEMA:bis> <SCHEMA:gesellschaft>AAA</SCHEMA:gesellschaft> <SCHEMA:shape> <gml:MultiPoint srsName="http://www.opengis.net/gml/srs/epsg.xml#31287"/> </SCHEMA:shape> </SCHEMA:TEST> </gml:featureMember>

Environment

None

Status

Assignee

Unassigned

Reporter

Stefan Murawski

Triage

None

Components

Affects versions

14-RC1
13.1

Priority

High
Configure