Changeset 18656 in josm


Ignore:
Timestamp:
2023-02-09T17:30:58+01:00 (15 months ago)
Author:
taylor.smock
Message:

Fix #22680: Unexpected exception when downloading GeoJSON

This occurs when we start to read the JSON, then something comes along and
interrupts the stream from the server. This then causes a JsonException
(a RuntimeException) to be thrown.

This patch catches the JsonException and then either rethrows it if the
cause was not an IOException or throws a new IllegalDataException with
the IOException as the cause and the JsonException as a suppressed exception.

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

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

    r17822 r18656  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.io.IOException;
    67import java.io.InputStream;
    78import java.util.Collection;
     
    1011import javax.json.Json;
    1112import javax.json.JsonArray;
     13import javax.json.JsonException;
    1214import javax.json.JsonNumber;
    1315import javax.json.JsonObject;
     
    179181    @Override
    180182    protected DataSet doParseDataSet(InputStream source, ProgressMonitor progressMonitor) throws IllegalDataException {
    181         return doParseDataSet(source, progressMonitor, ir -> {
    182             setParser(Json.createParser(ir));
    183             parse();
    184         });
     183        try {
     184            return doParseDataSet(source, progressMonitor, ir -> {
     185                setParser(Json.createParser(ir));
     186                parse();
     187            });
     188        } catch (JsonException exception) {
     189            if (exception.getCause() instanceof IOException) {
     190                IllegalDataException ide = new IllegalDataException(exception.getCause());
     191                // PMD 7 should be able to figure out that this is not an issue. See https://github.com/pmd/pmd/issues/2134 .
     192                ide.addSuppressed(exception);
     193                throw ide; // NOPMD
     194            } else {
     195                throw exception;
     196            }
     197        }
    185198    }
    186199
  • trunk/src/org/openstreetmap/josm/tools/HttpClient.java

    r18652 r18656  
    3434import org.openstreetmap.josm.io.auth.DefaultAuthenticator;
    3535import org.openstreetmap.josm.spi.preferences.Config;
    36 import org.openstreetmap.josm.tools.TextUtils;
    3736
    3837/**
Note: See TracChangeset for help on using the changeset viewer.