Ticket #24969: patch-Fix-Sonar-issues-in-TestAccessTokenTask.patch

File patch-Fix-Sonar-issues-in-TestAccessTokenTask.patch, 4.1 KB (added by DanProgs <Abenteurer.2901@…>, 3 hours ago)
  • src/org/openstreetmap/josm/gui/oauth/TestAccessTokenTask.java

    ### Eclipse Workspace Patch 1.0
    #P josm
    diff --git src/org/openstreetmap/josm/gui/oauth/TestAccessTokenTask.java src/org/openstreetmap/josm/gui/oauth/TestAccessTokenTask.java
    index ba6938d..0b84320 100644
     
    66import java.awt.Component;
    77import java.io.IOException;
    88import java.net.HttpURLConnection;
     9import java.net.URI;
    910import java.net.URL;
    1011
    1112import javax.swing.JOptionPane;
    … …  
    8586    protected UserInfo getUserDetails() throws OsmOAuthAuthorizationException, XmlParsingException, OsmTransferException {
    8687        boolean authenticatorEnabled = true;
    8788        try {
    88             URL url = new URL(apiUrl + "/0.6/user/details");
     89            final URL url = URI.create(apiUrl + "/0.6/user/details").toURL();
    8990            authenticatorEnabled = DefaultAuthenticator.getInstance().isEnabled();
    9091            DefaultAuthenticator.getInstance().setEnabled(false);
    9192
    … …  
    9798            }
    9899
    99100            final String oauthKey = getAuthKey();
    100             if (connection.getResponse().getResponseCode() == HttpURLConnection.HTTP_UNAUTHORIZED)
    101                 throw new OsmApiException(HttpURLConnection.HTTP_UNAUTHORIZED,
     101            if (connection.getResponse().getResponseCode() == HttpURLConnection.HTTP_UNAUTHORIZED) {
     102                throw new OsmApiException(HttpURLConnection.HTTP_UNAUTHORIZED,
    102103                        tr("Retrieving user details with Access Token Key ''{0}'' was rejected.",
    103104                                oauthKey), null);
     105            }
    104106
    105             if (connection.getResponse().getResponseCode() == HttpURLConnection.HTTP_FORBIDDEN)
    106                 throw new OsmApiException(HttpURLConnection.HTTP_FORBIDDEN,
     107            if (connection.getResponse().getResponseCode() == HttpURLConnection.HTTP_FORBIDDEN) {
     108                throw new OsmApiException(HttpURLConnection.HTTP_FORBIDDEN,
    107109                        tr("Retrieving user details with Access Token Key ''{0}'' was forbidden.", oauthKey), null);
     110            }
    108111
    109             if (connection.getResponse().getResponseCode() != HttpURLConnection.HTTP_OK)
    110                 throw new OsmApiException(connection.getResponse().getResponseCode(),
     112            if (connection.getResponse().getResponseCode() != HttpURLConnection.HTTP_OK) {
     113                throw new OsmApiException(connection.getResponse().getResponseCode(),
    111114                        connection.getResponse().getHeaderField("Error"), null);
    112             Document d = XmlUtils.parseSafeDOM(connection.getResponse().getContent());
     115            }
     116            final Document d = XmlUtils.parseSafeDOM(connection.getResponse().getContent());
    113117            return OsmServerUserInfoReader.buildFromXML(d);
    114118        } catch (SAXException | ParserConfigurationException e) {
    115119            throw new XmlParsingException(e);
    … …  
    233237    protected void realRun() throws SAXException, IOException, OsmTransferException {
    234238        try {
    235239            getProgressMonitor().indeterminateSubTask(tr("Retrieving user info..."));
    236             UserInfo userInfo = getUserDetails();
    237             if (canceled) return;
     240            final UserInfo userInfo = getUserDetails();
     241            if (canceled) {
     242                return;
     243            }
    238244            notifySuccess(userInfo);
    239245        } catch (OsmOAuthAuthorizationException e) {
    240             if (canceled) return;
     246            if (canceled) {
     247                return;
     248            }
    241249            Logging.error(e);
    242250            alertFailedSigning();
    243251        } catch (OsmApiException e) {
    244             if (canceled) return;
     252            if (canceled) {
     253                return;
     254            }
    245255            Logging.error(e);
    246256            if (e.getResponseCode() == HttpURLConnection.HTTP_INTERNAL_ERROR) {
    247257                alertInternalError();
    … …  
    255265            }
    256266            alertFailedConnection();
    257267        } catch (OsmTransferException e) {
    258             if (canceled) return;
     268            if (canceled) {
     269                return;
     270            }
    259271            Logging.error(e);
    260272            alertFailedConnection();
    261273        }