Changeset 10469 in josm


Ignore:
Timestamp:
2016-06-24T01:27:35+02:00 (8 years ago)
Author:
Don-vip
Message:

sonar - squid:S1166 - Exception handlers should preserve the original exceptions

Location:
trunk/src/org/openstreetmap/josm/data
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/AutosaveTask.java

    r10444 r10469  
    187187                }
    188188            } catch (IOException e) {
    189                 Main.error(tr("IOError while creating file, autosave will be skipped: {0}", e.getMessage()));
     189                Main.error(e, tr("IOError while creating file, autosave will be skipped: {0}", e.getMessage()));
    190190                return null;
    191191            }
  • trunk/src/org/openstreetmap/josm/data/CustomConfigurator.java

    r10404 r10469  
    9696
    9797    /**
     98     * Log an exception.
     99     * @param e exception to log
     100     * @param s message prefix
     101     * @since 10469
     102     */
     103    public static void log(Exception e, String s) {
     104        summary.append(s + ' ' + Main.getErrorMessage(e));
     105        summary.append('\n');
     106    }
     107
     108    /**
    98109     * Returns the log.
    99110     * @return the log
     
    273284            root = document.getDocumentElement();
    274285        } catch (SAXException | IOException | ParserConfigurationException ex) {
    275             Main.warn("Error getting preferences to save:" +ex.getMessage());
     286            Main.warn(ex, "Error getting preferences to save:");
    276287        }
    277288        if (root == null || exportDocument == null)
     
    454465                }
    455466            } catch (ScriptException | IOException | SecurityException ex) {
    456                 log("Error reading custom preferences: " + ex.getMessage());
     467                log(ex, "Error reading custom preferences:");
    457468            }
    458469        }
     
    465476                }
    466477            } catch (SAXException | IOException | ParserConfigurationException ex) {
    467                 log("Error reading custom preferences: "+ex.getMessage());
     478                log(ex, "Error reading custom preferences:");
    468479            }
    469480            log("-- Reading complete --");
     
    580591                    // we store this fragment as API.fragments['id']
    581592                } catch (ScriptException ex) {
    582                     log("Error: can not load preferences fragment : "+ex.getMessage());
     593                    log(ex, "Error: can not load preferences fragment:");
    583594                }
    584595            }
     
    664675                engine.eval(name+"='"+value+"';");
    665676            } catch (ScriptException ex) {
    666                 log("Error: Can not assign variable: %s=%s  : %s\n", name, value, ex.getMessage());
     677                log(ex, String.format("Error: Can not assign variable: %s=%s :", name, value));
    667678            }
    668679        }
     
    707718            } catch (ScriptException ex) {
    708719                messageBox("e", ex.getMessage());
    709                 log("JS error: "+ex.getMessage());
     720                log(ex, "JS error:");
    710721            }
    711722            log("Script finished");
     
    725736                    mr.appendReplacement(sb, result);
    726737                } catch (ScriptException ex) {
    727                     log("Error: Can not evaluate expression %s : %s", mr.group(1), ex.getMessage());
     738                    log(ex, String.format("Error: Can not evaluate expression %s :", mr.group(1)));
    728739                }
    729740            }
     
    746757                tmpPref.fromXML(reader);
    747758            } catch (TransformerException | XMLStreamException | IOException ex) {
    748                 log("Error: can not read XML fragment :" + ex.getMessage());
     759                log(ex, "Error: can not read XML fragment:");
    749760            }
    750761
  • trunk/src/org/openstreetmap/josm/data/Preferences.java

    r10380 r10469  
    909909                    save();
    910910                } catch (IOException e) {
    911                     Main.warn(tr("Failed to persist preferences to ''{0}''", getPreferenceFile().getAbsoluteFile()));
     911                    Main.warn(e, tr("Failed to persist preferences to ''{0}''", getPreferenceFile().getAbsoluteFile()));
    912912                }
    913913            }
     
    12511251            struct = klass.getConstructor().newInstance();
    12521252        } catch (ReflectiveOperationException ex) {
    1253             throw new RuntimeException(ex);
     1253            throw new IllegalArgumentException(ex);
    12541254        }
    12551255        for (Entry<String, String> key_value : hash.entrySet()) {
     
    12591259                f = klass.getDeclaredField(key_value.getKey().replace('-', '_'));
    12601260            } catch (NoSuchFieldException ex) {
     1261                Main.trace(ex);
    12611262                continue;
    12621263            }
  • trunk/src/org/openstreetmap/josm/data/cache/CacheEntryAttributes.java

    r10378 r10469  
    188188
    189189    /**
     190     * @param error error related to this object
     191     * @since 10469
     192     */
     193    public void setError(Exception error) {
     194        setErrorMessage(Main.getErrorMessage(error));
     195    }
     196
     197    /**
    190198     * @param message error message related to this object
    191199     */
  • trunk/src/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJob.java

    r10408 r10469  
    378378            log.log(Level.FINE, "JCS - Caching empty object as server returned 404 for: {0}", getUrlNoException());
    379379            attributes.setResponseCode(404);
    380             attributes.setErrorMessage(e.toString());
     380            attributes.setError(e);
    381381            boolean doCache = isResponseLoadable(null, 404, null) || cacheAsEmpty();
    382382            if (doCache) {
     
    387387        } catch (IOException e) {
    388388            log.log(Level.FINE, "JCS - IOExecption during communication with server for: {0}", getUrlNoException());
    389             attributes.setErrorMessage(e.toString());
     389            attributes.setError(e);
    390390            attributes.setResponseCode(499); // set dummy error code
    391391            boolean doCache = isResponseLoadable(null, 499, null) || cacheAsEmpty(); //generic 499 error code returned
     
    396396            return doCache;
    397397        } catch (InterruptedException e) {
    398             attributes.setErrorMessage(e.toString());
     398            attributes.setError(e);
    399399            log.log(Level.WARNING, "JCS - Exception during download {0}", getUrlNoException());
    400400            Main.warn(e);
  • trunk/src/org/openstreetmap/josm/data/imagery/CachedAttributionBingAerialTileSource.java

    r9970 r10469  
    7777                        return ret;
    7878                    } catch (IOException ex) {
    79                         Main.warn("Could not connect to Bing API. Will retry in " + waitTimeSec + " seconds.");
     79                        Main.warn(ex, "Could not connect to Bing API. Will retry in " + waitTimeSec + " seconds.");
    8080                        Thread.sleep(waitTimeSec * 1000L);
    8181                        waitTimeSec *= 2;
  • trunk/src/org/openstreetmap/josm/data/imagery/ImageryLayerInfo.java

    r10000 r10469  
    143143                OnlineResource.JOSM_WEBSITE.checkOfflineAccess(source, Main.getJOSMWebsite());
    144144            } catch (OfflineAccessException e) {
    145                 Main.warn(e.getMessage());
     145                Main.warn(e, false);
    146146                online = false;
    147147            }
  • trunk/src/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJob.java

    r10420 r10469  
    210210        } catch (IOException e) {
    211211            LOG.log(Level.WARNING, "JCS TMS - error loading object for tile {0}: {1}", new Object[] {tile.getKey(), e.getMessage()});
    212             tile.setError(e.toString());
     212            tile.setError(e);
    213213            tile.setLoaded(false);
    214214            if (listeners != null) { // listeners might be null, if some other thread notified already about success
  • trunk/src/org/openstreetmap/josm/data/osm/MultipolygonBuilder.java

    r9774 r10469  
    1919import java.util.concurrent.RecursiveTask;
    2020
     21import org.openstreetmap.josm.Main;
    2122import org.openstreetmap.josm.tools.Geometry;
    2223import org.openstreetmap.josm.tools.Geometry.PolygonIntersection;
     
    144145            return makeFromPolygons(joinedWays);
    145146        } catch (JoinedPolygonCreationException ex) {
     147            Main.debug(ex);
    146148            return ex.getMessage();
    147149        }
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r10378 r10469  
    875875            return SearchCompiler.compile(Main.pref.get(prefName, defaultValue));
    876876        } catch (ParseError e) {
    877             Main.error("Unable to compile pattern for " + prefName + ", trying default pattern: " + e.getMessage());
     877            Main.error(e, "Unable to compile pattern for " + prefName + ", trying default pattern:");
    878878        }
    879879
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/AbstractMapRenderer.java

    r10303 r10469  
    145145            // On read, it would first check, if the way still has firstIdx+2 nodes, then check if the corresponding way nodes are still
    146146            // the same and report changes in a more controlled manner.
    147             if (Main.isTraceEnabled()) {
    148                 Main.trace(e.getMessage());
    149             }
     147            Main.trace(e);
    150148        }
    151149    }
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapRendererFactory.java

    r10378 r10469  
    101101                return Class.forName(className, true, cl);
    102102            } catch (final NoClassDefFoundError | ClassNotFoundException e) {
    103                 Main.trace(e.getMessage());
     103                Main.trace(e);
    104104            }
    105105        }
     
    266266     * @see AbstractMapRenderer#AbstractMapRenderer(Graphics2D, NavigatableComponent, boolean)
    267267     */
    268     public AbstractMapRenderer createActiveRenderer(Graphics2D g, NavigatableComponent viewport, boolean isInactiveMode)
    269             throws MapRendererFactoryException {
     268    public AbstractMapRenderer createActiveRenderer(Graphics2D g, NavigatableComponent viewport, boolean isInactiveMode) {
    270269        try {
    271270            Constructor<?> c = activeRenderer.getConstructor(new Class<?>[]{Graphics2D.class, NavigatableComponent.class, boolean.class});
     
    274273            throw new MapRendererFactoryException(e);
    275274        } catch (InvocationTargetException e) {
     275            Main.debug(e);
    276276            throw new MapRendererFactoryException(e.getCause());
    277277        }
  • trunk/src/org/openstreetmap/josm/data/projection/CustomProjection.java

    r10378 r10469  
    205205            update(pref);
    206206        } catch (ProjectionConfigurationException ex) {
     207            Main.trace(ex);
    207208            try {
    208209                update(null);
  • trunk/src/org/openstreetmap/josm/data/projection/Projections.java

    r10212 r10469  
    324324                proj = pc.getProjection();
    325325            } catch (RuntimeException e) {
    326                 String cause = e.getMessage();
    327                 Main.warn("Unable to get projection "+code+" with "+pc + (cause != null ? ". "+cause : ""));
     326                Main.warn(e, "Unable to get projection "+code+" with "+pc+':');
    328327            }
    329328        }
  • trunk/src/org/openstreetmap/josm/data/validation/TestError.java

    r9989 r10469  
    361361                primitives = Collections.emptyList();
    362362            } else {
    363                 Main.warn("Unable to remove primitives from "+this);
     363                Main.warn(e, "Unable to remove primitives from "+this+'.');
    364364            }
    365365        }
  • trunk/src/org/openstreetmap/josm/data/validation/tests/ConditionalKeys.java

    r10300 r10469  
    1313import java.util.regex.Pattern;
    1414
     15import org.openstreetmap.josm.Main;
    1516import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1617import org.openstreetmap.josm.data.validation.Severity;
     
    141142            }
    142143        } catch (ConditionalParsingException ex) {
     144            Main.debug(ex);
    143145            return ex.getMessage();
    144146        }
  • trunk/src/org/openstreetmap/josm/data/validation/tests/InternetTags.java

    r9921 r10469  
    77import java.util.regex.Pattern;
    88
     9import org.openstreetmap.josm.Main;
    910import org.openstreetmap.josm.data.osm.Node;
    1011import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    107108                    error = doValidateTag(p, k, protocol+IDN.toASCII(domain)+ending, validator, code);
    108109                } catch (IllegalArgumentException e) {
     110                    Main.trace(e);
    109111                    error.setMessage(error.getMessage() +
    110112                            tr(" URL cannot be converted to ASCII: {0}", e.getMessage()));
  • trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java

    r10212 r10469  
    301301                            check.errors.put(ai, severity);
    302302                        } catch (IllegalArgumentException e) {
    303                             Main.warn("Unsupported "+ai.key+" instruction. Allowed instructions are "+POSSIBLE_THROWS);
     303                            Main.warn(e, "Unsupported "+ai.key+" instruction. Allowed instructions are "+POSSIBLE_THROWS+'.');
    304304                        }
    305305                    } else if ("fixAdd".equals(ai.key)) {
     
    436436                }
    437437            } catch (IndexOutOfBoundsException ignore) {
    438                 if (Main.isDebugEnabled()) {
    439                     Main.debug(ignore.getMessage());
    440                 }
     438                Main.debug(ignore);
    441439            }
    442440            return null;
     
    466464                    m.appendReplacement(sb, String.valueOf(argument).replace("^(", "").replace(")$", ""));
    467465                } catch (IndexOutOfBoundsException | IllegalArgumentException e) {
    468                     Main.error(tr("Unable to replace argument {0} in {1}: {2}", argument, sb, e.getMessage()));
     466                    Main.error(e, tr("Unable to replace argument {0} in {1}: {2}", argument, sb, e.getMessage()));
    469467                }
    470468            }
  • trunk/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java

    r10378 r10469  
    245245                }
    246246            } catch (IOException e) {
     247                Main.error(e);
    247248                errorSources.append(source).append('\n');
    248249            }
     
    294295                harmonizedKeys.put(harmonizeKey(ky.key), ky.key);
    295296            } catch (NullPointerException e) {
    296                 Main.error(p+": Unable to initialize "+ky);
     297                Main.error(e, p+": Unable to initialize "+ky+'.');
    297298            }
    298299        }
     
    783784                }
    784785            } catch (IllegalStateException e) {
     786                Main.error(e);
    785787                description = null;
    786788            }
     
    825827                    data.add(new CheckerElement(exp));
    826828                } catch (IllegalStateException e) {
     829                    Main.trace(e);
    827830                    return tr("Illegal expression ''{0}''", exp);
    828831                } catch (PatternSyntaxException e) {
     832                    Main.trace(e);
    829833                    return tr("Illegal regular expression ''{0}''", exp);
    830834                }
Note: See TracChangeset for help on using the changeset viewer.