Changeset 19662 in josm


Ignore:
Timestamp:
2026-10-24T13:43:40+02:00 (less than one hour ago)
Author:
stoecker
Message:

fix #24970 - patch by DanProgs (modified) - fix sonar issues

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/preferences/server/ApiUrlTestTask.java

    r19651 r19662  
    22package org.openstreetmap.josm.gui.preferences.server;
    33
     4import static org.openstreetmap.josm.tools.I18n.marktr;
    45import static org.openstreetmap.josm.tools.I18n.tr;
    56
    … …  
    89import java.net.HttpURLConnection;
    910import java.net.MalformedURLException;
     11import java.net.URI;
    1012import java.net.URL;
    1113
    … …  
    3840    private final Component parent;
    3941    private HttpClient connection;
     42
     43    private static final String CONNECTION_FAILED_MSG = marktr("Connection to API failed");
    4044
    4145    /**
    … …  
    9498                        url
    9599                ),
    96                 tr("Connection to API failed"),
     100                tr(CONNECTION_FAILED_MSG),
    97101                JOptionPane.ERROR_MESSAGE,
    98102                HelpUtil.ht("/Preferences/Connection#ConnectionToAPIFailed")
    … …  
    111115                        url
    112116                ),
    113                 tr("Connection to API failed"),
     117                tr(CONNECTION_FAILED_MSG),
    114118                JOptionPane.ERROR_MESSAGE,
    115119                HelpUtil.ht("/Preferences/Connection#InvalidServerResult")
    … …  
    127131                        url
    128132                ),
    129                 tr("Connection to API failed"),
     133                tr(CONNECTION_FAILED_MSG),
    130134                JOptionPane.ERROR_MESSAGE,
    131135                HelpUtil.ht("/Preferences/Connection#InvalidSettings")
    … …  
    152156        try {
    153157            try {
    154                 new URL(url);
    155             } catch (MalformedURLException e) {
     158                URI.create(url).toURL();
     159            } catch (IllegalArgumentException | MalformedURLException e) {
    156160                alertInvalidUrl(url);
    157161                return;
    158162            }
    159             URL capabilitiesUrl;
    160             String getCapabilitiesUrl = url + "/0.6/capabilities";
     163            final URL capabilitiesUrl;
     164            final String getCapabilitiesUrl = url + "/0.6/capabilities";
    161165            try {
    162                 capabilitiesUrl = new URL(getCapabilitiesUrl);
    163             } catch (MalformedURLException e) {
     166                capabilitiesUrl = URI.create(getCapabilitiesUrl).toURL();
     167            } catch (IllegalArgumentException | MalformedURLException e) {
    164168                alertInvalidCapabilitiesUrl(getCapabilitiesUrl);
    165169                return;
    … …  
    171175            }
    172176
    173             if (connection.getResponse().getResponseCode() != HttpURLConnection.HTTP_OK) {
    174                 alertInvalidServerResult(connection.getResponse().getResponseCode());
     177            final int responseCode = connection.getResponse().getResponseCode();
     178            if (responseCode  != HttpURLConnection.HTTP_OK) {
     179                alertInvalidServerResult(responseCode );
    175180                return;
    176181            }
    … …  
    185190            success = true;
    186191        } catch (IOException e) {
    187             if (canceled)
     192            if (canceled) {
    188193                // ignore exceptions
    189194                return;
     195            }
    190196            Logging.error(e);
    191197            alertConnectionFailed();
Note: See TracChangeset for help on using the changeset viewer.