Changeset 18581 in josm for trunk/src/org


Ignore:
Timestamp:
2022-10-24T20:54:43+02:00 (18 months ago)
Author:
taylor.smock
Message:

Fix #21431: Failed to download data in LoadAndZoomHandler

ExceptionDialogUtil.explainException has special handling for OsmTransferException.
Unfortunately, it requires that the exception have a cause set, and not only are we not
setting the cause, we weren't even adding any additional suppressed exceptions.

This does currently produce two notification windows for the same problem.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/LoadAndZoomHandler.java

    r18200 r18581  
    1010import java.util.Collections;
    1111import java.util.LinkedHashSet;
     12import java.util.List;
    1213import java.util.Map;
    1314import java.util.Set;
     
    1617import java.util.concurrent.TimeUnit;
    1718import java.util.concurrent.TimeoutException;
     19import java.util.stream.Collectors;
    1820
    1921import javax.swing.JOptionPane;
     
    165167                                if (osmTask.isFailed()) {
    166168                                    Object error = osmTask.getErrorObjects().get(0);
    167                                     throw error instanceof OsmApiException
    168                                         ? (OsmApiException) error
    169                                         : new OsmTransferException(String.join(", ", osmTask.getErrorMessages()));
     169                                    if (error instanceof OsmApiException) {
     170                                        throw (OsmApiException) error;
     171                                    }
     172                                    List<Throwable> exceptions = osmTask.getErrorObjects().stream()
     173                                                    .filter(Throwable.class::isInstance).map(Throwable.class::cast)
     174                                                    .collect(Collectors.toList());
     175                                    OsmTransferException osmTransferException =
     176                                            new OsmTransferException(String.join(", ", osmTask.getErrorMessages()));
     177                                    if (!exceptions.isEmpty()) {
     178                                        osmTransferException.initCause(exceptions.get(0));
     179                                        exceptions.remove(0);
     180                                        exceptions.forEach(osmTransferException::addSuppressed);
     181                                    }
     182                                    throw osmTransferException;
    170183                                }
    171184                            } catch (InterruptedException | ExecutionException | TimeoutException |
Note: See TracChangeset for help on using the changeset viewer.