Ignore:
Timestamp:
2017-02-14T23:00:03+01:00 (7 years ago)
Author:
Don-vip
Message:

fix #14368 - java.util.regex.PatternSyntaxException: Unclosed group

Location:
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ConditionFactory.java

    r11454 r11562  
    1414import java.util.function.Predicate;
    1515import java.util.regex.Pattern;
     16import java.util.regex.PatternSyntaxException;
    1617
    1718import org.openstreetmap.josm.Main;
     
    5152     * @param considerValAsKey whether to consider {@code v} as another key and compare the values of key {@code k} and key {@code v}.
    5253     * @return The new condition.
     54     * @throws MapCSSException if the arguments are incorrect
    5355     */
    5456    public static Condition createKeyValueCondition(String k, String v, Op op, Context context, boolean considerValAsKey) {
    5557        switch (context) {
    5658        case PRIMITIVE:
    57             if (KeyValueRegexpCondition.SUPPORTED_OPS.contains(op) && !considerValAsKey)
    58                 return new KeyValueRegexpCondition(k, v, op, false);
     59            if (KeyValueRegexpCondition.SUPPORTED_OPS.contains(op) && !considerValAsKey) {
     60                try {
     61                    return new KeyValueRegexpCondition(k, v, op, false);
     62                } catch (PatternSyntaxException e) {
     63                    throw new MapCSSException(e);
     64                }
     65            }
    5966            if (!considerValAsKey && op.equals(Op.EQ))
    6067                return new SimpleKeyValueCondition(k, v);
     
    339346         * @param op operation
    340347         * @param considerValAsKey must be false
     348         * @throws PatternSyntaxException if the value syntax is invalid
    341349         */
    342350        public KeyValueRegexpCondition(String k, String v, Op op, boolean considerValAsKey) {
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSException.java

    r6987 r11562  
    22package org.openstreetmap.josm.gui.mappaint.mapcss;
    33
     4/**
     5 * MapCSS parsing error, with line/columnn information in error message.
     6 */
    47public class MapCSSException extends RuntimeException {
    58
    6     protected final String specialmessage;
     9    /** line number at which the parse error occured */
    710    protected Integer line;
     11    /** column number at which the parse error occured */
    812    protected Integer column;
    913
     14    /**
     15     * Constructs a new {@code MapCSSException} with an explicit error message.
     16     * @param specialmessage error message
     17     */
    1018    public MapCSSException(String specialmessage) {
    11         this.specialmessage = specialmessage;
     19        super(specialmessage);
    1220    }
    1321
     22    /**
     23     * Constructs a new {@code MapCSSException} with a cause.
     24     * @param cause the root cause
     25     * @since 11562
     26     */
     27    public MapCSSException(Throwable cause) {
     28        super(cause);
     29    }
     30
     31    /**
     32     * Sets the column number at which the parse error occured.
     33     * @param column the column number at which the parse error occured
     34     */
    1435    public void setColumn(int column) {
    1536        this.column = column;
    1637    }
    1738
     39    /**
     40     * Sets the line number at which the parse error occured.
     41     * @param line the line number at which the parse error occured
     42     */
    1843    public void setLine(int line) {
    1944        this.line = line;
     
    2348    public String getMessage() {
    2449        if (line == null || column == null)
    25             return specialmessage;
    26         return String.format("Error at line %s, column %s: %s", line, column, specialmessage);
     50            return super.getMessage();
     51        return String.format("Error at line %s, column %s: %s", line, column, super.getMessage());
    2752    }
    2853}
Note: See TracChangeset for help on using the changeset viewer.