Changeset 17356 in josm for trunk


Ignore:
Timestamp:
2020-11-25T10:26:24+01:00 (4 years ago)
Author:
simon04
Message:

see #20152 - GeoJSONReader: better exception for illegal FeatureCollection

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/GeoJSONReader.java

    r17185 r17356  
    4545import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    4646import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     47import org.openstreetmap.josm.tools.CheckParameterUtil;
    4748import org.openstreetmap.josm.tools.Logging;
    4849import org.openstreetmap.josm.tools.Utils;
     
    8586                .orElseThrow(() -> new IllegalDataException("No type")).getString()) {
    8687            case "FeatureCollection":
     88                JsonValue.ValueType valueType = object.get(FEATURES).getValueType();
     89                CheckParameterUtil.ensureThat(valueType == JsonValue.ValueType.ARRAY, "features must be ARRAY, but is " + valueType);
    8790                parseFeatureCollection(object.getJsonArray(FEATURES));
    8891                break;
  • trunk/test/unit/org/openstreetmap/josm/io/GeoJSONReaderTest.java

    r17275 r17356  
    216216    }
    217217
     218    /**
     219     * Tests error reporting for an invalid FeatureCollection
     220     * @throws Exception in case of error
     221     */
     222    @Test
     223    void testInvalidFeatureCollection() throws Exception {
     224        String featureCollection = "{\"type\": \"FeatureCollection\", \"features\": {}}";
     225        try (InputStream in = new ByteArrayInputStream(featureCollection.getBytes(StandardCharsets.UTF_8))) {
     226            IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
     227                    () -> new GeoJSONReader().doParseDataSet(in, null));
     228            assertEquals("features must be ARRAY, but is OBJECT", exception.getMessage());
     229        }
     230    }
     231
    218232}
Note: See TracChangeset for help on using the changeset viewer.