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/actions
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/AddImageryLayerAction.java

    r9918 r10212  
    5454
    5555        // change toolbar icon from if specified
    56         try {
    57             String icon = info.getIcon();
    58             if (icon != null) {
    59                 new ImageProvider(icon).setOptional(true).getInBackground(new ImageResourceCallback() {
    60                             @Override
    61                             public void finished(final ImageResource result) {
    62                                 if (result != null) {
    63                                     GuiHelper.runInEDT(new Runnable() {
    64                                         @Override
    65                                         public void run() {
    66                                             result.getImageIcon(AddImageryLayerAction.this);
    67                                         }
    68                                     });
    69                                 }
     56        String icon = info.getIcon();
     57        if (icon != null) {
     58            new ImageProvider(icon).setOptional(true).getInBackground(new ImageResourceCallback() {
     59                        @Override
     60                        public void finished(final ImageResource result) {
     61                            if (result != null) {
     62                                GuiHelper.runInEDT(new Runnable() {
     63                                    @Override
     64                                    public void run() {
     65                                        result.getImageIcon(AddImageryLayerAction.this);
     66                                    }
     67                                });
    7068                            }
    71                         });
    72             }
    73         } catch (Exception ex) {
    74             throw new RuntimeException(ex.getMessage(), ex);
     69                        }
     70                    });
    7571        }
    7672    }
  • trunk/src/org/openstreetmap/josm/actions/CloseChangesetAction.java

    r9519 r10212  
    137137                        getProgressMonitor().createSubTaskMonitor(1, false /* not internal */)
    138138                );
    139             } catch (Exception e) {
     139            } catch (OsmTransferException | IllegalArgumentException e) {
    140140                if (canceled)
    141141                    return;
  • trunk/src/org/openstreetmap/josm/actions/JosmAction.java

    r10074 r10212  
    66import java.awt.event.KeyEvent;
    77import java.util.Collection;
     8import java.util.concurrent.CancellationException;
     9import java.util.concurrent.ExecutionException;
    810import java.util.concurrent.Future;
    911
     
    239241                        try {
    240242                            future.get();
    241                         } catch (Exception e) {
     243                        } catch (InterruptedException | ExecutionException | CancellationException e) {
    242244                            Main.error(e);
    243245                            return;
  • trunk/src/org/openstreetmap/josm/actions/OpenFileAction.java

    r9972 r10212  
    2525import java.util.regex.Matcher;
    2626import java.util.regex.Pattern;
     27import java.util.regex.PatternSyntaxException;
    2728
    2829import javax.swing.JOptionPane;
     
    328329                            }
    329330                        }
    330                     } catch (Exception e) {
     331                    } catch (IOException | PatternSyntaxException | IllegalStateException | IndexOutOfBoundsException e) {
    331332                        Main.error(e);
    332333                    }
  • trunk/src/org/openstreetmap/josm/actions/OpenLocationAction.java

    r9972 r10212  
    153153                        result.add(task);
    154154                    }
    155                 } catch (Exception e) {
     155                } catch (ReflectiveOperationException e) {
    156156                    Main.error(e);
    157157                }
     
    173173                    DownloadTask task = taskClass.getConstructor().newInstance();
    174174                    result.append(task.acceptsDocumentationSummary());
    175                 } catch (Exception e) {
     175                } catch (ReflectiveOperationException e) {
    176176                    Main.error(e);
    177177                }
  • trunk/src/org/openstreetmap/josm/actions/RestartAction.java

    r9238 r10212  
    7979
    8080    /**
    81      * Restarts the current Java application
    82      * @throws IOException in case of any error
     81     * Restarts the current Java application.
     82     * @throws IOException in case of any I/O error
    8383     */
    8484    public static void restartJOSM() throws IOException {
    8585        if (isRestartSupported() && !Main.exitJosm(false, 0)) return;
    8686        final List<String> cmd;
    87         try {
    88             // special handling for OSX .app package
    89             if (Main.isPlatformOsx() && System.getProperty("java.library.path").contains("/JOSM.app/Contents/MacOS")) {
    90                 cmd = getAppleCommands();
    91             } else {
    92                 cmd = getCommands();
    93             }
    94             Main.info("Restart "+cmd);
    95             if (Main.isDebugEnabled() && Main.pref.getBoolean("restart.debug.simulation")) {
    96                 Main.debug("Restart cancelled to get debug info");
    97                 return;
    98             }
    99             // execute the command in a shutdown hook, to be sure that all the
    100             // resources have been disposed before restarting the application
    101             Runtime.getRuntime().addShutdownHook(new Thread("josm-restarter") {
    102                 @Override
    103                 public void run() {
    104                     try {
    105                         Runtime.getRuntime().exec(cmd.toArray(new String[cmd.size()]));
    106                     } catch (IOException e) {
    107                         Main.error(e);
    108                     }
     87        // special handling for OSX .app package
     88        if (Main.isPlatformOsx() && System.getProperty("java.library.path").contains("/JOSM.app/Contents/MacOS")) {
     89            cmd = getAppleCommands();
     90        } else {
     91            cmd = getCommands();
     92        }
     93        Main.info("Restart "+cmd);
     94        if (Main.isDebugEnabled() && Main.pref.getBoolean("restart.debug.simulation")) {
     95            Main.debug("Restart cancelled to get debug info");
     96            return;
     97        }
     98        // execute the command in a shutdown hook, to be sure that all the
     99        // resources have been disposed before restarting the application
     100        Runtime.getRuntime().addShutdownHook(new Thread("josm-restarter") {
     101            @Override
     102            public void run() {
     103                try {
     104                    Runtime.getRuntime().exec(cmd.toArray(new String[cmd.size()]));
     105                } catch (IOException e) {
     106                    Main.error(e);
    109107                }
    110             });
    111             // exit
    112             System.exit(0);
    113         } catch (Exception e) {
    114             // something went wrong
    115             throw new IOException("Error while trying to restart the application", e);
    116         }
     108            }
     109        });
     110        // exit
     111        System.exit(0);
    117112    }
    118113
  • trunk/src/org/openstreetmap/josm/actions/SessionLoadAction.java

    r10192 r10212  
    183183            } catch (IOException e) {
    184184                handleException(tr("IO Error"), e);
    185             } catch (Exception e) {
     185            } catch (RuntimeException e) {
    186186                cancel();
    187187                throw e;
  • trunk/src/org/openstreetmap/josm/actions/UpdateSelectionAction.java

    r9241 r10212  
    2323import org.openstreetmap.josm.io.MultiFetchServerObjectReader;
    2424import org.openstreetmap.josm.io.OnlineResource;
     25import org.openstreetmap.josm.io.OsmTransferException;
    2526import org.openstreetmap.josm.tools.Shortcut;
    2627
     
    4445            DataSet ds = reader.parseOsm(NullProgressMonitor.INSTANCE);
    4546            Main.main.getEditLayer().mergeFrom(ds);
    46         } catch (Exception e) {
     47        } catch (OsmTransferException e) {
    4748            ExceptionDialogUtil.explainException(e);
    4849        }
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java

    r9509 r10212  
    115115                ProgressMonitor subMonitor = progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false);
    116116                rawData = reader.parseRawGps(subMonitor);
    117             } catch (Exception e) {
     117            } catch (OsmTransferException e) {
    118118                if (isCanceled())
    119119                    return;
    120                 if (e instanceof OsmTransferException) {
    121                     rememberException(e);
    122                 } else {
    123                     rememberException(new OsmTransferException(e));
    124                 }
     120                rememberException(e);
    125121            }
    126122        }
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadNotesTask.java

    r10032 r10212  
    160160                                + "</html>",
    161161                        tr("More notes to download"), JOptionPane.INFORMATION_MESSAGE);
    162             } catch (Exception e) {
     162            } catch (OsmTransferException e) {
    163163                if (isCanceled())
    164164                    return;
    165                 if (e instanceof OsmTransferException) {
    166                     rememberException(e);
    167                 } else {
    168                     rememberException(new OsmTransferException(e));
    169                 }
     165                rememberException(e);
    170166            }
    171167        }
     
    186182            try {
    187183                notesData = reader.parseRawNotes(subMonitor);
    188             } catch (Exception e) {
     184            } catch (OsmTransferException e) {
    189185                if (isCanceled())
    190186                    return;
    191                 if (e instanceof OsmTransferException) {
    192                     rememberException(e);
    193                 } else {
    194                     rememberException(new OsmTransferException(e));
    195                 }
     187                rememberException(e);
    196188            }
    197189        }
     
    212204            try {
    213205                notesData = reader.parseRawNotesBzip2(subMonitor);
    214             } catch (Exception e) {
     206            } catch (OsmTransferException e) {
    215207                if (isCanceled())
    216208                    return;
    217                 if (e instanceof OsmTransferException) {
    218                     rememberException(e);
    219                 } else {
    220                     rememberException(new OsmTransferException(e));
    221                 }
     209                rememberException(e);
    222210            }
    223211        }
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java

    r9732 r10212  
    332332                    return;
    333333                dataSet = parseDataSet();
    334             } catch (Exception e) {
     334            } catch (OsmTransferException e) {
    335335                if (isCanceled()) {
    336336                    Main.info(tr("Ignoring exception because download has been canceled. Exception was: {0}", e.toString()));
     
    340340                    setCanceled(true);
    341341                    return;
    342                 } else if (e instanceof OsmTransferException) {
     342                } else {
    343343                    rememberException(e);
    344                 } else {
    345                     rememberException(new OsmTransferException(e));
    346344                }
    347345                DownloadOsmTask.this.setFailed(true);
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadReferrersTask.java

    r9881 r10212  
    194194                i++;
    195195            }
    196         } catch (Exception e) {
     196        } catch (OsmTransferException e) {
    197197            if (canceled)
    198198                return;
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadTaskList.java

    r10135 r10212  
    1616import java.util.List;
    1717import java.util.Set;
     18import java.util.concurrent.CancellationException;
     19import java.util.concurrent.ExecutionException;
    1820import java.util.concurrent.Future;
    1921
     
    249251                try {
    250252                    future.get();
    251                 } catch (Exception e) {
     253                } catch (InterruptedException | ExecutionException | CancellationException e) {
    252254                    Main.error(e);
    253255                    return;
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/PostDownloadHandler.java

    r9905 r10212  
    99import java.util.LinkedHashSet;
    1010import java.util.Set;
     11import java.util.concurrent.CancellationException;
     12import java.util.concurrent.ExecutionException;
    1113import java.util.concurrent.Future;
    1214
     
    4042        try {
    4143            future.get();
    42         } catch (Exception e) {
     44        } catch (InterruptedException | ExecutionException | CancellationException e) {
    4345            Main.error(e);
    4446            return;
  • trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java

    r9981 r10212  
    598598                } catch (PatternSyntaxException e) {
    599599                    throw new ParseError(tr(rxErrorMsg, e.getPattern(), e.getIndex(), e.getMessage()), e);
    600                 } catch (Exception e) {
     600                } catch (IllegalArgumentException e) {
    601601                    throw new ParseError(tr(rxErrorMsgNoPos, key, e.getMessage()), e);
    602602                }
     
    605605                } catch (PatternSyntaxException e) {
    606606                    throw new ParseError(tr(rxErrorMsg, e.getPattern(), e.getIndex(), e.getMessage()), e);
    607                 } catch (Exception e) {
     607                } catch (IllegalArgumentException e) {
    608608                    throw new ParseError(tr(rxErrorMsgNoPos, value, e.getMessage()), e);
    609609                }
     
    795795                } catch (PatternSyntaxException e) {
    796796                    throw new ParseError(tr(rxErrorMsg, e.getPattern(), e.getIndex(), e.getMessage()), e);
    797                 } catch (Exception e) {
     797                } catch (IllegalArgumentException e) {
    798798                    throw new ParseError(tr(rxErrorMsgNoPos, key, e.getMessage()), e);
    799799                }
     
    806806                } catch (PatternSyntaxException e) {
    807807                    throw new ParseError(tr(rxErrorMsg, e.getPattern(), e.getIndex(), e.getMessage()), e);
    808                 } catch (Exception e) {
     808                } catch (IllegalArgumentException e) {
    809809                    throw new ParseError(tr(rxErrorMsgNoPos, value, e.getMessage()), e);
    810810                }
     
    885885                } catch (PatternSyntaxException e) {
    886886                    throw new ParseError(tr(rxErrorMsg, e.getPattern(), e.getIndex(), e.getMessage()), e);
    887                 } catch (Exception e) {
     887                } catch (IllegalArgumentException e) {
    888888                    throw new ParseError(tr(rxErrorMsgNoPos, s, e.getMessage()), e);
    889889                }
  • trunk/src/org/openstreetmap/josm/actions/upload/UploadNotesTask.java

    r10134 r10212  
    117117                }
    118118                updatedNotes.put(note, newNote);
    119             } catch (Exception e) {
     119            } catch (OsmTransferException e) {
    120120                Main.error("Failed to upload note to server: " + note.getId());
    121121                Main.error(e);
Note: See TracChangeset for help on using the changeset viewer.