citygml4j / citygml-tools

Collection of tools for processing CityGML files
Apache License 2.0
115 stars 18 forks source link

IndexOutOfBoundsException if Building/boundedBy/Envelope is declared but empty #5

Closed kannes closed 5 years ago

kannes commented 5 years ago

I had a file with a declared but blank boundedBy/Envelope per Building:

...
  <core:cityObjectMember>
    <bldg:Building gml:id="foobar">
      <gml:boundedBy>
        <gml:Envelope srsName="urn:ogc:def:crs,crs:EPSG:6.12:25832,crs:EPSG:6.12:5783" srsDimension="3">
          <gml:lowerCorner/>
          <gml:upperCorner/>
        </gml:Envelope>
      </gml:boundedBy>
...

Trying to convert that to CityJSON gave me:

$ bash /tmp/citygml-tools-1.3.0/bin/citygml-tools to-cityjson sample.gml
[13:51:03 INFO] Starting citygml-tools.
[13:51:03 INFO] Initializing application environment.
[13:51:04 INFO] Executing command 'to-cityjson'.
[13:51:04 INFO] Found 1 file(s) at 'sample.gml'.
[13:51:04 INFO] [1|1] Processing file '/tmp/sample.gml'.
[13:51:04 INFO] Writing output to file '/tmp/sample.json'.
[13:51:05 ERROR] The following unexpected error occurred during execution.
picocli.CommandLine$ExecutionException: Error while executing command (org.citygml4j.tools.command.ToCityJSONCommand@22a0d4ea): java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
    at org.citygml4j.tools.CityGMLTools.handleParseResult(CityGMLTools.java:113)
    at org.citygml4j.tools.CityGMLTools.handleParseResult(CityGMLTools.java:35)
    at picocli.CommandLine.parseWithHandlers(CommandLine.java:1526)
    at org.citygml4j.tools.CityGMLTools.main(CityGMLTools.java:46)
Caused by: java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
    at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
    at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
    at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248)
    at java.base/java.util.Objects.checkIndex(Objects.java:372)
    at java.base/java.util.ArrayList.get(ArrayList.java:458)
    at org.citygml4j.model.gml.geometry.primitives.Envelope.toBoundingBox(Envelope.java:414)
    at org.citygml4j.model.gml.geometry.primitives.Envelope.isNull(Envelope.java:384)
    at org.citygml4j.model.gml.feature.BoundingShape.setEnvelope(BoundingShape.java:71)
    at org.citygml4j.builder.jaxb.unmarshal.gml.GMLUnmarshaller.unmarshalBoundingShape(GMLUnmarshaller.java:997)
    at org.citygml4j.builder.jaxb.unmarshal.gml.GMLUnmarshaller.unmarshalAbstractFeature(GMLUnmarshaller.java:518)
    at org.citygml4j.builder.jaxb.unmarshal.citygml.core.Core100Unmarshaller.unmarshalAbstractCityObject(Core100Unmarshaller.java:119)
    at org.citygml4j.builder.jaxb.unmarshal.citygml.core.Core100Unmarshaller.unmarshalAbstractSite(Core100Unmarshaller.java:160)
    at org.citygml4j.builder.jaxb.unmarshal.citygml.building.Building100Unmarshaller.unmarshalAbstractBuilding(Building100Unmarshaller.java:147)
    at org.citygml4j.builder.jaxb.unmarshal.citygml.building.Building100Unmarshaller.unmarshalBuilding(Building100Unmarshaller.java:328)
    at org.citygml4j.builder.jaxb.unmarshal.citygml.building.Building100Unmarshaller.unmarshalBuilding(Building100Unmarshaller.java:341)
    at org.citygml4j.util.mapper.CheckedTypeMapper.apply(CheckedTypeMapper.java:52)
    at org.citygml4j.builder.jaxb.unmarshal.citygml.building.Building100Unmarshaller.unmarshal(Building100Unmarshaller.java:143)
    at org.citygml4j.builder.jaxb.unmarshal.citygml.building.Building100Unmarshaller.unmarshal(Building100Unmarshaller.java:139)
    at org.citygml4j.builder.jaxb.unmarshal.citygml.CityGMLUnmarshaller.unmarshal(CityGMLUnmarshaller.java:191)
    at org.citygml4j.builder.jaxb.unmarshal.JAXBUnmarshaller.unmarshal(JAXBUnmarshaller.java:68)
    at org.citygml4j.builder.jaxb.unmarshal.citygml.core.Core100Unmarshaller.unmarshalCityObjectMember(Core100Unmarshaller.java:233)
    at org.citygml4j.builder.jaxb.unmarshal.gml.GMLUnmarshaller.unmarshalAbstractFeatureCollection(GMLUnmarshaller.java:563)
    at org.citygml4j.builder.jaxb.unmarshal.citygml.core.Core100Unmarshaller.unmarshalCityModel(Core100Unmarshaller.java:210)
    at org.citygml4j.builder.jaxb.unmarshal.citygml.core.Core100Unmarshaller.unmarshalCityModel(Core100Unmarshaller.java:223)
    at org.citygml4j.util.mapper.CheckedTypeMapper.apply(CheckedTypeMapper.java:52)
    at org.citygml4j.builder.jaxb.unmarshal.citygml.core.Core100Unmarshaller.unmarshal(Core100Unmarshaller.java:115)
    at org.citygml4j.builder.jaxb.unmarshal.citygml.core.Core100Unmarshaller.unmarshal(Core100Unmarshaller.java:111)
    at org.citygml4j.builder.jaxb.unmarshal.citygml.CityGMLUnmarshaller.unmarshal(CityGMLUnmarshaller.java:197)
    at org.citygml4j.builder.jaxb.unmarshal.JAXBUnmarshaller.unmarshal(JAXBUnmarshaller.java:68)
    at org.citygml4j.builder.jaxb.xml.io.reader.JAXBSimpleReader.nextFeature(JAXBSimpleReader.java:168)
    at org.citygml4j.tools.command.ToCityJSONCommand.execute(ToCityJSONCommand.java:126)
    at org.citygml4j.tools.CityGMLTools.handleParseResult(CityGMLTools.java:109)
    ... 3 more
[13:51:05 WARN] citygml-tools execution failed.

After I removed the nonsense the conversion worked:

$ bash /tmp/citygml-tools-1.3.0/bin/citygml-tools to-cityjson sample_without.gml 
[13:52:49 INFO] Starting citygml-tools.
[13:52:49 INFO] Initializing application environment.
[13:52:50 INFO] Executing command 'to-cityjson'.
[13:52:50 INFO] Found 1 file(s) at 'sample_without.gml '.
[13:52:50 INFO] [1|1] Processing file '/tmp/sample_without.gml '.
[13:52:50 INFO] Writing output to file '/sample_without.json'.
[13:52:51 INFO] Total execution time: 02 s.
[13:52:51 INFO] citygml-tools successfully completed.

I don't know how bad the data is, if this is a data issue or not. But this cost me way too many hairs so I thought I'd post it here. Maybe it is a software bug and citygml4j should be able to handle this kind of GML.

clausnagel commented 5 years ago

Thanks for reporting this bug. I fixed it in citygml4j (https://github.com/citygml4j/citygml4j/commit/031e8b41c275aa212779a9f363abbbe407507ae9). The fix will be included in the next citygml-tools release.

kannes commented 5 years ago

Awesome!

clausnagel commented 5 years ago

Just released v1.3.1 which contains the bugfix.

kannes commented 5 years ago

Sweet, thanks!