Changeset 18658 in josm for trunk/src


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

See #22680: Unexpected exception when downloading GeoJSON

This primarily adds a non-regression test, but also narrows the IOException
to SocketException to better match the exception type and adds a specific
catch for parsing issues.

File:
1 edited

Legend:

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

    r18656 r18658  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
    6 import java.io.IOException;
    76import java.io.InputStream;
     7import java.net.SocketException;
    88import java.util.Collection;
    99import java.util.Map.Entry;
     
    1818import javax.json.stream.JsonParser;
    1919import javax.json.stream.JsonParser.Event;
     20import javax.json.stream.JsonParsingException;
    2021
    2122import org.openstreetmap.josm.data.osm.DataSet;
     
    186187                parse();
    187188            });
     189        } catch (JsonParsingException exception) {
     190            throw new IllegalDataException(exception);
    188191        } 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             }
     192            if (exception.getCause() instanceof SocketException) {
     193                SocketException soe = (SocketException) exception.getCause();
     194                soe.addSuppressed(exception); // Add the caught exception as a suppressed exception
     195                throw new IllegalDataException(soe); // NOPMD -- PreserveStackTrace should be fixed with PMD 7
     196            }
     197            throw exception;
    197198        }
    198199    }
Note: See TracChangeset for help on using the changeset viewer.