Ignore:
Timestamp:
2016-05-15T00:51:10+02:00 (8 years ago)
Author:
Don-vip
Message:

sonar - squid:S2221 - "Exception" should not be caught when not required by called methods

Location:
trunk/src/org/openstreetmap/josm/io
Files:
21 edited

Legend:

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

    r10194 r10212  
    192192        } catch (OsmTransferException e) {
    193193            throw e;
    194         } catch (Exception e) {
     194        } catch (IllegalDataException | IOException e) {
    195195            throw new OsmTransferException(e);
    196196        } finally {
  • trunk/src/org/openstreetmap/josm/io/CachedFile.java

    r10194 r10212  
    352352                Utils.close(zipFile);
    353353            }
    354         } catch (Exception e) {
     354        } catch (IOException e) {
    355355            if (file.getName().endsWith(".zip")) {
    356356                Main.warn(tr("Failed to open file with extension ''{2}'' and namepart ''{3}'' in zip file ''{0}''. Exception was: {1}",
  • trunk/src/org/openstreetmap/josm/io/FileImporter.java

    r9231 r10212  
    9999            }
    100100            return false;
    101         } catch (Exception e) {
     101        } catch (IOException e) {
    102102            displayError(f, e);
    103103            return false;
     
    138138            importData(files, progressMonitor);
    139139            return true;
    140         } catch (Exception e) {
     140        } catch (IOException | IllegalDataException e) {
    141141            Main.error(e);
    142142            HelpAwareOptionPane.showMessageDialogInEDT(
  • trunk/src/org/openstreetmap/josm/io/GpxReader.java

    r10045 r10212  
    409409                    try {
    410410                        currentWayPoint.put(localName, Float.valueOf(accumulator.toString()));
    411                     } catch (Exception e) {
     411                    } catch (NumberFormatException e) {
    412412                        currentWayPoint.put(localName, 0f);
    413413                    }
  • trunk/src/org/openstreetmap/josm/io/MultiFetchServerObjectReader.java

    r9325 r10212  
    522522                try {
    523523                    result = new FetchResult(OsmReader.parseDataSet(in, progressMonitor.createSubTaskMonitor(pkg.size(), false)), null);
    524                 } catch (Exception e) {
     524                } catch (IllegalDataException e) {
    525525                    throw new OsmTransferException(e);
    526526                }
     
    550550                try {
    551551                    result = OsmReader.parseDataSet(in, progressMonitor.createSubTaskMonitor(1, false));
    552                 } catch (Exception e) {
     552                } catch (IllegalDataException e) {
    553553                    throw new OsmTransferException(e);
    554554                }
  • trunk/src/org/openstreetmap/josm/io/OsmApi.java

    r10051 r10212  
    263263            Main.addNetworkError(url, Utils.getRootCause(e));
    264264            throw new OsmApiInitializationException(e);
    265         } catch (Exception e) {
     265        } catch (SAXException | IOException | ParserConfigurationException e) {
    266266            initialized = false;
    267267            throw new OsmApiInitializationException(e);
  • trunk/src/org/openstreetmap/josm/io/OsmApiException.java

    r8513 r10212  
    144144                .append('>');
    145145            }
    146         } catch (Exception e) {
     146        } catch (IllegalArgumentException e) {
    147147            // Ignored
    148148            if (Main.isTraceEnabled()) {
     
    157157                .append('>');
    158158            }
    159         } catch (Exception e) {
     159        } catch (IllegalArgumentException e) {
    160160            // Ignored
    161161            if (Main.isTraceEnabled()) {
  • trunk/src/org/openstreetmap/josm/io/OsmChangesetParser.java

    r10001 r10212  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.io.IOException;
    67import java.io.InputStream;
    78import java.io.InputStreamReader;
     
    283284        } catch (ParserConfigurationException | SAXException e) {
    284285            throw new IllegalDataException(e.getMessage(), e);
    285         } catch (Exception e) {
     286        } catch (IOException e) {
    286287            throw new IllegalDataException(e);
    287288        } finally {
  • trunk/src/org/openstreetmap/josm/io/OsmReader.java

    r9326 r10212  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.io.IOException;
    67import java.io.InputStream;
    78import java.io.InputStreamReader;
     
    651652            else
    652653                throw new IllegalDataException(msg, e);
    653         } catch (Exception e) {
     654        } catch (IOException e) {
    654655            throw new IllegalDataException(e);
    655656        } finally {
  • trunk/src/org/openstreetmap/josm/io/OsmServerBackreferenceReader.java

    r9231 r10212  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.io.IOException;
    67import java.io.InputStream;
    78import java.text.MessageFormat;
     
    135136        } catch (OsmTransferException e) {
    136137            throw e;
    137         } catch (Exception e) {
     138        } catch (IOException | IllegalDataException e) {
    138139            if (cancel)
    139140                return null;
  • trunk/src/org/openstreetmap/josm/io/OsmServerHistoryReader.java

    r9231 r10212  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.io.IOException;
    67import java.io.InputStream;
    78import java.text.MessageFormat;
     
    1213import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    1314import org.openstreetmap.josm.tools.CheckParameterUtil;
     15import org.xml.sax.SAXException;
    1416
    1517/**
     
    7274        } catch (OsmTransferException e) {
    7375            throw e;
    74         } catch (Exception e) {
     76        } catch (IOException | SAXException e) {
    7577            if (cancel)
    7678                return null;
  • trunk/src/org/openstreetmap/josm/io/OsmServerLocationReader.java

    r9990 r10212  
    5252        } catch (OsmTransferException e) {
    5353            throw e;
    54         } catch (Exception e) {
     54        } catch (IOException | SAXException | IllegalDataException e) {
    5555            if (cancel)
    5656                return null;
  • trunk/src/org/openstreetmap/josm/io/OsmServerObjectReader.java

    r8510 r10212  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.io.IOException;
    67import java.io.InputStream;
    78import java.text.MessageFormat;
     
    134135            if (cancel) return null;
    135136            throw e;
    136         } catch (Exception e) {
     137        } catch (IOException | IllegalDataException e) {
    137138            if (cancel) return null;
    138139            throw new OsmTransferException(e);
  • trunk/src/org/openstreetmap/josm/io/OsmServerReader.java

    r9732 r10212  
    144144            try {
    145145                response = client.connect(progressMonitor);
    146             } catch (Exception e) {
     146            } catch (IOException e) {
    147147                Main.error(e);
    148148                OsmTransferException ote = new OsmTransferException(
     
    163163                    try {
    164164                        errorBody = response.fetchContent();
    165                     } catch (Exception e) {
     165                    } catch (IOException e) {
    166166                        errorBody = tr("Reading error text failed.");
    167167                    }
     
    173173            } catch (OsmTransferException e) {
    174174                throw e;
    175             } catch (Exception e) {
     175            } catch (IOException e) {
    176176                throw new OsmTransferException(e);
    177177            }
  • trunk/src/org/openstreetmap/josm/io/OsmServerUserInfoReader.java

    r8540 r10212  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.io.IOException;
    67import java.io.InputStream;
    78import java.util.LinkedList;
     
    910
    1011import javax.xml.parsers.DocumentBuilderFactory;
     12import javax.xml.parsers.ParserConfigurationException;
    1113import javax.xml.xpath.XPath;
    1214import javax.xml.xpath.XPathConstants;
     
    2325import org.w3c.dom.Node;
    2426import org.w3c.dom.NodeList;
     27import org.xml.sax.SAXException;
    2528
    2629public class OsmServerUserInfoReader extends OsmServerReader {
     
    178181        } catch (OsmTransferException e) {
    179182            throw e;
    180         } catch (Exception e) {
     183        } catch (IOException | ParserConfigurationException | SAXException e) {
    181184            throw new OsmTransferException(e);
    182185        } finally {
  • trunk/src/org/openstreetmap/josm/io/imagery/WMSImagery.java

    r9171 r10212  
    1919import javax.xml.parsers.DocumentBuilder;
    2020import javax.xml.parsers.DocumentBuilderFactory;
     21import javax.xml.parsers.ParserConfigurationException;
    2122
    2223import org.openstreetmap.josm.Main;
     
    142143            builderFactory.setValidating(false);
    143144            builderFactory.setNamespaceAware(true);
    144             DocumentBuilder builder = null;
    145             builder = builderFactory.newDocumentBuilder();
     145            DocumentBuilder builder = builderFactory.newDocumentBuilder();
    146146            builder.setEntityResolver(new EntityResolver() {
    147147                @Override
     
    151151                }
    152152            });
    153             Document document = null;
    154             document = builder.parse(new InputSource(new StringReader(incomingData)));
     153            Document document = builder.parse(new InputSource(new StringReader(incomingData)));
    155154
    156155            // Some WMS service URLs specify a different base URL for their GetMap service
     
    193192            List<Element> children = getChildren(capabilityElem, "Layer");
    194193            layers = parseLayers(children, new HashSet<String>());
    195         } catch (Exception e) {
     194        } catch (MalformedURLException | ParserConfigurationException | SAXException e) {
    196195            throw new WMSGetCapabilitiesException(e, incomingData);
    197196        }
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/RemoteControlHttpServer.java

    r9078 r10212  
    3636            instance4 = new RemoteControlHttpServer(port, false);
    3737            instance4.start();
    38         } catch (Exception ex) {
     38        } catch (IOException ex) {
    3939            Main.warn(marktr("Cannot start IPv4 remotecontrol server on port {0}: {1}"),
    4040                    Integer.toString(port), ex.getLocalizedMessage());
     
    4343            instance6 = new RemoteControlHttpServer(port, true);
    4444            instance6.start();
    45         } catch (Exception ex) {
     45        } catch (IOException ex) {
    4646            /* only show error when we also have no IPv4 */
    4747            if (instance4 == null) {
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/RemoteControlHttpsServer.java

    r10060 r10212  
    333333                instance4 = new RemoteControlHttpsServer(port, false);
    334334                instance4.start();
    335             } catch (Exception ex) {
     335            } catch (IOException | GeneralSecurityException ex) {
    336336                Main.warn(marktr("Cannot start IPv4 remotecontrol https server on port {0}: {1}"),
    337337                        Integer.toString(port), ex.getLocalizedMessage());
     
    340340                instance6 = new RemoteControlHttpsServer(port, true);
    341341                instance6.start();
    342             } catch (Exception ex) {
     342            } catch (IOException | GeneralSecurityException ex) {
    343343                /* only show error when we also have no IPv4 */
    344344                if (instance4 == null) {
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/ImportHandler.java

    r9732 r10212  
    4747                }
    4848            }
    49         } catch (Exception ex) {
     49        } catch (RuntimeException ex) {
    5050            Main.warn("RemoteControl: Error parsing import remote control request:");
    5151            Main.error(ex);
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/LoadAndZoomHandler.java

    r10131 r10212  
    145145                }
    146146            }
    147         } catch (Exception ex) {
     147        } catch (RuntimeException ex) {
    148148            Main.warn("RemoteControl: Error parsing load_and_zoom remote control request:");
    149149            Main.error(ex);
  • trunk/src/org/openstreetmap/josm/io/session/SessionWriter.java

    r9746 r10212  
    99import java.io.OutputStream;
    1010import java.io.OutputStreamWriter;
    11 import java.lang.reflect.Constructor;
    1211import java.nio.charset.StandardCharsets;
    1312import java.util.ArrayList;
     
    9796            return null;
    9897        try {
    99             Constructor<? extends SessionLayerExporter> constructor = exporterClass.getConstructor(layerClass);
    100             return constructor.newInstance(layer);
    101         } catch (Exception e) {
     98            return exporterClass.getConstructor(layerClass).newInstance(layer);
     99        } catch (ReflectiveOperationException e) {
    102100            throw new RuntimeException(e);
    103101        }
Note: See TracChangeset for help on using the changeset viewer.