Ignore:
Timestamp:
2016-05-17T02:02:30+02:00 (5 years ago)
Author:
Don-vip
Message:

sonar - squid:S00112 - Generic exceptions should never be thrown

Location:
trunk/src/org/openstreetmap/josm/data/preferences
Files:
4 edited

Legend:

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

    r9759 r10235  
    7474        if (value != null) {
    7575            if (value.contains(null))
    76                 throw new RuntimeException("Error: Null as list element in preference setting");
     76                throw new IllegalArgumentException("Error: Null as list element in preference setting");
    7777            for (Collection<String> lst : value) {
    7878                if (lst.contains(null)) {
    79                     throw new RuntimeException("Error: Null as inner list element in preference setting");
     79                    throw new IllegalArgumentException("Error: Null as inner list element in preference setting");
    8080                }
    8181            }
  • trunk/src/org/openstreetmap/josm/data/preferences/ListSetting.java

    r9759 r10235  
    4444    private void consistencyTest() {
    4545        if (value != null && value.contains(null))
    46             throw new RuntimeException("Error: Null as list element in preference setting");
     46            throw new IllegalArgumentException("Error: Null as list element in preference setting");
    4747    }
    4848
  • trunk/src/org/openstreetmap/josm/data/preferences/MapListSetting.java

    r9759 r10235  
    7373            return;
    7474        if (value.contains(null))
    75             throw new RuntimeException("Error: Null as list element in preference setting");
     75            throw new IllegalArgumentException("Error: Null as list element in preference setting");
    7676        for (Map<String, String> map : value) {
    7777            if (map.keySet().contains(null))
    78                 throw new RuntimeException("Error: Null as map key in preference setting");
     78                throw new IllegalArgumentException("Error: Null as map key in preference setting");
    7979            if (map.values().contains(null))
    80                 throw new RuntimeException("Error: Null as map value in preference setting");
     80                throw new IllegalArgumentException("Error: Null as map value in preference setting");
    8181        }
    8282    }
  • trunk/src/org/openstreetmap/josm/data/preferences/PreferencesReader.java

    r9978 r10235  
    3131import org.openstreetmap.josm.Main;
    3232import org.openstreetmap.josm.io.CachedFile;
     33import org.openstreetmap.josm.io.XmlStreamParsingException;
    3334import org.xml.sax.SAXException;
    3435
     
    3738 */
    3839public class PreferencesReader {
    39 
    40     private static final String XSI_NS = "http://www.w3.org/2001/XMLSchema-instance";
    4140
    4241    private final SortedMap<String, Setting<?>> settings = new TreeMap<>();
     
    118117    }
    119118
     119    /**
     120     * Parse preferences.
     121     * @throws XMLStreamException if any XML parsing error occurs
     122     * @throws IOException if any I/O error occurs
     123     */
    120124    public void parse() throws XMLStreamException, IOException {
    121125        if (reader != null) {
     
    168172                switch(localName) {
    169173                case "tag":
    170                     Setting setting;
     174                    StringSetting setting;
    171175                    if (defaults && isNil()) {
    172176                        setting = new StringSetting(null);
     
    221225        List<Map<String, String>> maps = null;
    222226        if (defaults && isNil()) {
    223             Setting setting;
     227            Setting<?> setting;
    224228            switch (name) {
    225229                case "lists":
     
    268272                }
    269273            }
    270             Setting setting;
     274            Setting<?> setting;
    271275            if (entries != null) {
    272276                setting = new ListSetting(Collections.unmodifiableList(entries));
     
    337341     */
    338342    private boolean isNil() {
    339         String nil = parser.getAttributeValue(XSI_NS, "nil");
     343        String nil = parser.getAttributeValue(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "nil");
    340344        return "true".equals(nil) || "1".equals(nil);
    341345    }
    342346
    343347    /**
    344      * Throw RuntimeException with line and column number.
     348     * Throw XmlStreamParsingException with line and column number.
    345349     *
    346350     * Only use this for errors that should not be possible after schema validation.
    347351     * @param msg the error message
    348      */
    349     private void throwException(String msg) {
    350         throw new RuntimeException(msg + tr(" (at line {0}, column {1})",
    351                 parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber()));
     352     * @throws XmlStreamParsingException always
     353     */
     354    private void throwException(String msg) throws XmlStreamParsingException {
     355        throw new XmlStreamParsingException(msg, parser.getLocation());
    352356    }
    353357}
Note: See TracChangeset for help on using the changeset viewer.