Changeset 7417 in josm for trunk/src


Ignore:
Timestamp:
2014-08-16T11:56:17+02:00 (10 years ago)
Author:
Don-vip
Message:

fix #10380 - throw IllegalDataException instead of RuntimeException with invalid TagChecker rules

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java

    r7356 r7417  
    5252import org.openstreetmap.josm.gui.preferences.validator.ValidatorTagCheckerRulesPreference;
    5353import org.openstreetmap.josm.io.CachedFile;
     54import org.openstreetmap.josm.io.IllegalDataException;
    5455import org.openstreetmap.josm.io.UTFInputStreamReader;
    5556import org.openstreetmap.josm.tools.CheckParameterUtil;
     
    195196        }
    196197
    197         static TagCheck ofMapCSSRule(final GroupedMapCSSRule rule) {
     198        static TagCheck ofMapCSSRule(final GroupedMapCSSRule rule) throws IllegalDataException {
    198199            final TagCheck check = new TagCheck(rule);
    199200            boolean containsSetClassExpression = false;
     
    244245                        check.assertions.put(val, false);
    245246                    } else {
    246                         throw new RuntimeException("Cannot add instruction " + ai.key + ": " + ai.val + "!");
     247                        throw new IllegalDataException("Cannot add instruction " + ai.key + ": " + ai.val + "!");
    247248                    }
    248249                }
    249250            }
    250251            if (check.errors.isEmpty() && !containsSetClassExpression) {
    251                 throw new RuntimeException("No "+POSSIBLE_THROWS+" given! You should specify a validation error message for " + rule.selectors);
     252                throw new IllegalDataException("No "+POSSIBLE_THROWS+" given! You should specify a validation error message for " + rule.selectors);
    252253            } else if (check.errors.size() > 1) {
    253                 throw new RuntimeException("More than one "+POSSIBLE_THROWS+" given! You should specify a single validation error message for " + rule.selectors);
     254                throw new IllegalDataException("More than one "+POSSIBLE_THROWS+" given! You should specify a single validation error message for " + rule.selectors);
    254255            }
    255256            return check;
     
    281282            List<TagCheck> result = new ArrayList<>();
    282283            for (Map.Entry<Declaration, List<Selector>> map : g.entrySet()) {
    283                 result.add(TagCheck.ofMapCSSRule(
    284                         new GroupedMapCSSRule(map.getValue(), map.getKey())));
     284                try {
     285                    result.add(TagCheck.ofMapCSSRule(
     286                            new GroupedMapCSSRule(map.getValue(), map.getKey())));
     287                } catch (IllegalDataException e) {
     288                    Main.error("Cannot add MapCss rule: "+e.getMessage());
     289                }
    285290            }
    286291            return result;
  • trunk/src/org/openstreetmap/josm/io/IllegalDataException.java

    r3083 r7417  
    22package org.openstreetmap.josm.io;
    33
    4 public class IllegalDataException extends Exception{
     4/**
     5 * Generic exception raised when illegal data is read.
     6 * @since 2070
     7 */
     8public class IllegalDataException extends Exception {
    59
    6     public IllegalDataException() {
    7         super();
    8     }
    9 
     10    /**
     11     * Constructs a new {@code IllegalDataException}.
     12     * @param message the detail message (which is saved for later retrieval
     13     *         by the {@link #getMessage()} method).
     14     * @param cause the cause (which is saved for later retrieval by the
     15     *         {@link #getCause()} method).
     16     */
    1017    public IllegalDataException(String message, Throwable cause) {
    1118        super(message, cause);
    1219    }
    1320
     21    /**
     22     * Constructs a new {@code IllegalDataException}.
     23     * @param message the detail message (which is saved for later retrieval
     24     *         by the {@link #getMessage()} method).
     25     */
    1426    public IllegalDataException(String message) {
    1527        super(message);
    1628    }
    1729
     30    /**
     31     * Constructs a new {@code IllegalDataException}.
     32     * @param cause the cause (which is saved for later retrieval by the
     33     *         {@link #getCause()} method).
     34     */
    1835    public IllegalDataException(Throwable cause) {
    1936        super(cause);
    2037    }
    21 
    2238}
Note: See TracChangeset for help on using the changeset viewer.