Changeset 7864 in josm for trunk/src


Ignore:
Timestamp:
2014-12-20T22:43:20+01:00 (5 years ago)
Author:
Don-vip
Message:

global cleanup of IllegalArgumentExceptions thrown by JOSM

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

Legend:

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

    r7852 r7864  
    1515import org.openstreetmap.josm.gui.Notification;
    1616import org.openstreetmap.josm.gui.dialogs.NotesDialog;
     17import org.openstreetmap.josm.tools.CheckParameterUtil;
    1718import org.openstreetmap.josm.tools.ImageProvider;
    1819
     
    3435            tr("Add note mode"),
    3536            mapFrame, ImageProvider.getCursor("crosshair", "create_note"));
    36         if (data == null) {
    37             throw new IllegalArgumentException("Note data must not be null");
    38         }
     37        CheckParameterUtil.ensureParameterNotNull(data, "data");
    3938        noteData = data;
    4039    }
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitiveType.java

    r6889 r7864  
    4747            if (type.getAPIName().equals(typeName)) return type;
    4848        }
    49         throw new IllegalArgumentException(MessageFormat.format("Parameter ''{0}'' is not a valid type name. Got ''{1}''.", "typeName", typeName));
     49        throw new IllegalArgumentException(MessageFormat.format(
     50                "Parameter ''{0}'' is not a valid type name. Got ''{1}''.", "typeName", typeName));
    5051    }
    5152
     53    /**
     54     * Determines the OSM primitive type of the given object.
     55     * @param obj the S object to inspect
     56     * @return the OSM primitive type of {@code obj}
     57     * @throws IllegalArgumentException if {@code obj} is null or of unknown type
     58     */
    5259    public static OsmPrimitiveType from(IPrimitive obj) {
    5360        if (obj instanceof INode) return NODE;
    5461        if (obj instanceof IWay) return WAY;
    5562        if (obj instanceof IRelation) return RELATION;
    56         throw new IllegalArgumentException();
     63        throw new IllegalArgumentException("Unknown type: "+obj);
    5764    }
    5865
  • trunk/src/org/openstreetmap/josm/data/osm/RelationMember.java

    r6305 r7864  
    33
    44import java.util.Arrays;
     5
     6import org.openstreetmap.josm.tools.CheckParameterUtil;
    57
    68/**
     
    128130     * @throws IllegalArgumentException thrown if member is <code>null</code>
    129131     */
    130     public RelationMember(String role, OsmPrimitive member) throws IllegalArgumentException{
     132    public RelationMember(String role, OsmPrimitive member) {
     133        CheckParameterUtil.ensureParameterNotNull(member, "member");
    131134        if (role == null) {
    132135            role = "";
    133136        }
    134         if (member == null)
    135             throw new IllegalArgumentException("Relation member cannot be null");
    136137        this.role = role;
    137138        this.member = member;
  • trunk/src/org/openstreetmap/josm/gui/ExtendedDialog.java

    r7545 r7864  
    527527    public ExtendedDialog toggleEnable(String togglePref) {
    528528        if (!modal) {
    529             throw new IllegalArgumentException();
     529            throw new IllegalStateException();
    530530        }
    531531        this.toggleable = true;
  • trunk/src/org/openstreetmap/josm/gui/MainApplication.java

    r7843 r7864  
    266266                values.add(g.getOptarg());
    267267            } else
    268                 throw new IllegalArgumentException();
     268                throw new IllegalArgumentException("Invalid option: "+c);
    269269        }
    270270        // positional arguments are a shortcut for the --download ... option
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/ListMergeModel.java

    r7017 r7864  
    372372    private void copy(ListRole sourceRole, int[] rows, int position) {
    373373        if (position < 0 || position > getMergedEntriesSize())
    374             throw new IllegalArgumentException();
     374            throw new IllegalArgumentException("Position must be between 0 and "+getMergedEntriesSize()+" but is "+position);
    375375        List<T> newItems = new ArrayList<>(rows.length);
    376376        List<T> source = entries.get(sourceRole);
  • trunk/src/org/openstreetmap/josm/gui/dialogs/DialogsPanel.java

    r7005 r7864  
    1010import javax.swing.JSplitPane;
    1111
    12 import org.openstreetmap.josm.gui.widgets.MultiSplitPane;
    1312import org.openstreetmap.josm.gui.widgets.MultiSplitLayout.Divider;
    1413import org.openstreetmap.josm.gui.widgets.MultiSplitLayout.Leaf;
    1514import org.openstreetmap.josm.gui.widgets.MultiSplitLayout.Node;
    1615import org.openstreetmap.josm.gui.widgets.MultiSplitLayout.Split;
     16import org.openstreetmap.josm.gui.widgets.MultiSplitPane;
     17import org.openstreetmap.josm.tools.CheckParameterUtil;
    1718import org.openstreetmap.josm.tools.Destroyable;
    1819
     
    161162            }
    162163        } else {
    163             if (triggeredBy == null)
    164                 throw new IllegalArgumentException();
     164            CheckParameterUtil.ensureParameterNotNull(triggeredBy, "triggeredBy");
    165165
    166166            int sumP = 0;   // sum of preferred heights of dialogs in default view (without the triggering dialog)
  • trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java

    r7823 r7864  
    8181import org.openstreetmap.josm.io.OsmTransferException;
    8282import org.openstreetmap.josm.io.UTFInputStreamReader;
     83import org.openstreetmap.josm.tools.CheckParameterUtil;
    8384import org.openstreetmap.josm.tools.Utils;
    8485import org.xml.sax.InputSource;
     
    111112    public static final IntegerProperty PROP_TMS_JOBS = new IntegerProperty("tmsloader.maxjobs", 25);
    112113    public static final StringProperty PROP_TILECACHE_DIR;
    113    
     114
    114115    private static final boolean newcache = Main.pref.getBoolean("tms.newcache");
    115116
     
    401402    }
    402403
    403     public static void checkUrl(String url) throws IllegalArgumentException {
    404         if (url == null) {
    405             throw new IllegalArgumentException();
    406         } else {
    407             Matcher m = Pattern.compile("\\{[^}]*\\}").matcher(url);
    408             while (m.find()) {
    409                 boolean isSupportedPattern = false;
    410                 for (String pattern : TemplatedTMSTileSource.ALL_PATTERNS) {
    411                     if (m.group().matches(pattern)) {
    412                         isSupportedPattern = true;
    413                         break;
    414                     }
    415                 }
    416                 if (!isSupportedPattern) {
    417                     throw new IllegalArgumentException(tr("{0} is not a valid TMS argument. Please check this server URL:\n{1}", m.group(), url));
    418                 }
     404    /**
     405     * Checks validity of given URL.
     406     * @param url URL to check
     407     * @throws IllegalArgumentException if url is null or invalid
     408     */
     409    public static void checkUrl(String url) {
     410        CheckParameterUtil.ensureParameterNotNull(url, "url");
     411        Matcher m = Pattern.compile("\\{[^}]*\\}").matcher(url);
     412        while (m.find()) {
     413            boolean isSupportedPattern = false;
     414            for (String pattern : TemplatedTMSTileSource.ALL_PATTERNS) {
     415                if (m.group().matches(pattern)) {
     416                    isSupportedPattern = true;
     417                    break;
     418                }
     419            }
     420            if (!isSupportedPattern) {
     421                throw new IllegalArgumentException(
     422                        tr("{0} is not a valid TMS argument. Please check this server URL:\n{1}", m.group(), url));
    419423            }
    420424        }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/Cascade.java

    r7509 r7864  
    4242    public <T> T get(String key, T def, Class<T> klass, boolean suppressWarnings) {
    4343        if (def != null && !klass.isInstance(def))
    44             throw new IllegalArgumentException();
     44            throw new IllegalArgumentException(def+" is not an instance of "+klass);
    4545        Object o = prop.get(key);
    4646        if (o == null)
  • trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java

    r7621 r7864  
    4545        public Symbol(SymbolShape symbol, int size, Stroke stroke, Color strokeColor, Color fillColor) {
    4646            if (stroke != null && strokeColor == null)
    47                 throw new IllegalArgumentException();
     47                throw new IllegalArgumentException("Stroke given without color");
    4848            if (stroke == null && fillColor == null)
    49                 throw new IllegalArgumentException();
     49                throw new IllegalArgumentException("Either a stroke or a fill color must be given");
    5050            this.symbol = symbol;
    5151            this.size = size;
  • trunk/src/org/openstreetmap/josm/gui/mappaint/Range.java

    r7069 r7864  
    1313    public static final Range ZERO_TO_INFINITY = new Range(0.0, Double.POSITIVE_INFINITY);
    1414
     15    /**
     16     * Constructs a new {@code Range}.
     17     * @param lower Lower bound. Must be positive or zero
     18     * @param upper Upper bound
     19     * @throws IllegalArgumentException if the range is invalid ({@code lower < 0 || lower >= upper})
     20     */
    1521    public Range(double lower, double upper) {
    1622        if (lower < 0 || lower >= upper)
    17             throw new IllegalArgumentException();
     23            throw new IllegalArgumentException("Invalid range: "+lower+"-"+upper);
    1824        this.lower = lower;
    1925        this.upper = upper;
     
    2935    public static Range cut(Range a, Range b) {
    3036        if (b.lower >= a.upper || b.upper <= a.lower)
    31             throw new IllegalArgumentException();
     37            throw new IllegalArgumentException("Ranges do not overlap: "+a+" - "+b);
    3238        return new Range(Math.max(a.lower, b.lower), Math.min(a.upper, b.upper));
    3339    }
     
    4955    public Range reduceAround(double x, Range other) {
    5056        if (!contains(x))
    51             throw new IllegalArgumentException();
     57            throw new IllegalArgumentException(x+" is not inside "+this);
    5258        if (other.contains(x))
    53             throw new IllegalArgumentException();
     59            throw new IllegalArgumentException(x+" is inside "+other);
    5460
    5561        if (x < other.lower && other.lower < upper)
  • trunk/src/org/openstreetmap/josm/gui/mappaint/StyleCache.java

    r7083 r7864  
    105105    public StyleList get(double scale) {
    106106        if (scale <= 0)
    107             throw new IllegalArgumentException();
     107            throw new IllegalArgumentException("scale must be <= 0 but is "+scale);
    108108        for (int i=0; i<data.size(); ++i) {
    109109            if (bd.get(i) < scale && scale <= bd.get(i+1)) {
     
    120120    public Pair<StyleList, Range> getWithRange(double scale) {
    121121        if (scale <= 0)
    122             throw new IllegalArgumentException();
     122            throw new IllegalArgumentException("scale must be <= 0 but is "+scale);
    123123        for (int i=0; i<data.size(); ++i) {
    124124            if (bd.get(i) < scale && scale <= bd.get(i+1)) {
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java

    r7801 r7864  
    592592        public static double level2scale(int lvl) {
    593593            if (lvl < 0)
    594                 throw new IllegalArgumentException();
     594                throw new IllegalArgumentException("lvl must be >= 0 but is "+lvl);
    595595            // preliminary formula - map such that mapnik imagery tiles of the same
    596596            // or similar level are displayed at the given scale
     
    600600        public static int scale2level(double scale) {
    601601            if (scale < 0)
    602                 throw new IllegalArgumentException();
     602                throw new IllegalArgumentException("scale must be >= 0 but is "+scale);
    603603            return (int) Math.floor(Math.log(2 * Math.PI * R / 2.56 / scale) / Math.log(2));
    604604        }
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/AbstractProjectionChoice.java

    r7184 r7864  
    3535    public AbstractProjectionChoice(String name, String id) {
    3636        this(name, id, null);
    37         if (!id.startsWith("core:")) throw new IllegalArgumentException();
     37        if (!id.startsWith("core:")) throw new IllegalArgumentException(id+" does not start with core:");
    3838        this.cacheDir = id.substring(5);
    3939    }
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/CodeProjectionChoice.java

    r7668 r7864  
    215215    public Collection<String> getPreferences(JPanel panel) {
    216216        if (!(panel instanceof CodeSelectionPanel)) {
    217             throw new IllegalArgumentException();
     217            throw new IllegalArgumentException("Unsupported panel: "+panel);
    218218        }
    219219        CodeSelectionPanel csPanel = (CodeSelectionPanel) panel;
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/CustomProjectionChoice.java

    r7668 r7864  
    232232    public Collection<String> getPreferences(JPanel panel) {
    233233        if (!(panel instanceof PreferencePanel)) {
    234             throw new IllegalArgumentException();
     234            throw new IllegalArgumentException("Unsupported panel: "+panel);
    235235        }
    236236        PreferencePanel prefPanel = (PreferencePanel) panel;
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/ListProjectionChoice.java

    r7015 r7864  
    106106    public Collection<String> getPreferences(JPanel panel) {
    107107        if (!(panel instanceof CBPanel)) {
    108             throw new IllegalArgumentException();
     108            throw new IllegalArgumentException("Unsupported panel: "+panel);
    109109        }
    110110        CBPanel p = (CBPanel) panel;
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/UTMProjectionChoice.java

    r7668 r7864  
    106106    public Collection<String> getPreferences(JPanel panel) {
    107107        if (!(panel instanceof UTMPanel)) {
    108             throw new IllegalArgumentException();
     108            throw new IllegalArgumentException("Unsupported panel: "+panel);
    109109        }
    110110        UTMPanel p = (UTMPanel) panel;
  • trunk/src/org/openstreetmap/josm/gui/tagging/TagEditorModel.java

    r7024 r7864  
    176176     */
    177177    public void add(TagModel tag) {
    178         if (tag == null)
    179             throw new IllegalArgumentException("argument 'tag' must not be null");
     178        CheckParameterUtil.ensureParameterNotNull(tag, "tag");
    180179        tags.add(tag);
    181180        setDirty(true);
     
    184183
    185184    public void prepend(TagModel tag) {
    186         if (tag == null)
    187             throw new IllegalArgumentException("argument 'tag' must not be null");
     185        CheckParameterUtil.ensureParameterNotNull(tag, "tag");
    188186        tags.add(0, tag);
    189187        setDirty(true);
  • trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletingComboBox.java

    r7863 r7864  
    223223            cbEditor.setItem(((AutoCompletionListItem)item).getValue());
    224224        } else
    225             throw new IllegalArgumentException();
     225            throw new IllegalArgumentException("Unsupported item: "+item);
    226226    }
    227227
  • trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionList.java

    r7725 r7864  
    1111import javax.swing.JTable;
    1212import javax.swing.table.AbstractTableModel;
     13
     14import org.openstreetmap.josm.tools.CheckParameterUtil;
    1315
    1416/**
     
    5860     */
    5961    public void applyFilter(String filter) {
    60         if (filter == null)
    61             throw new IllegalArgumentException("argument 'filter' must not be null");
     62        CheckParameterUtil.ensureParameterNotNull(filter, "filter");
    6263        this.filter = filter;
    6364        filter();
     
    102103     */
    103104    public void add(AutoCompletionList other) {
    104         if (other == null)
    105             throw new IllegalArgumentException("argument 'other' must not be null");
     105        CheckParameterUtil.ensureParameterNotNull(other, "other");
    106106        for (AutoCompletionListItem item : other.list) {
    107107            appendOrUpdatePriority(item);
     
    119119     */
    120120    public void add(List<AutoCompletionListItem> other) {
    121         if (other == null)
    122             throw new IllegalArgumentException("argument 'other' must not be null");
     121        CheckParameterUtil.ensureParameterNotNull(other, "other");
    123122        for (AutoCompletionListItem toadd : other) {
    124123            appendOrUpdatePriority(toadd);
     
    148147        filter();
    149148    }
    150    
     149
    151150    public void addUserInput(Collection<String> values) {
    152151        if (values == null) return;
  • trunk/src/org/openstreetmap/josm/gui/widgets/MultiSplitLayout.java

    r7025 r7864  
    4343
    4444import org.openstreetmap.josm.Main;
     45import org.openstreetmap.josm.tools.CheckParameterUtil;
    4546import org.openstreetmap.josm.tools.Utils;
    4647
     
    828829     */
    829830    public List<Divider> dividersThatOverlap(Rectangle r) {
    830         if (r == null)
    831             throw new IllegalArgumentException("null Rectangle");
     831        CheckParameterUtil.ensureParameterNotNull(r, "r");
    832832        return dividersThatOverlap(getModel(), r);
    833833    }
     
    886886         */
    887887        public void setBounds(Rectangle bounds) {
    888             if (bounds == null)
    889                 throw new IllegalArgumentException("null bounds");
     888            CheckParameterUtil.ensureParameterNotNull(bounds, "bounds");
    890889            this.bounds = new Rectangle(bounds);
    891890        }
     
    10771076         */
    10781077        public Leaf(String name) {
    1079             if (name == null)
    1080                 throw new IllegalArgumentException("name is null");
     1078            CheckParameterUtil.ensureParameterNotNull(name, "name");
    10811079            this.name = name;
    10821080        }
     
    10971095         */
    10981096        public void setName(String name) {
    1099             if (name == null)
    1100                 throw new IllegalArgumentException("name is null");
     1097            CheckParameterUtil.ensureParameterNotNull(name, "name");
    11011098            this.name = name;
    11021099        }
  • trunk/src/org/openstreetmap/josm/tools/ExifReader.java

    r7592 r7864  
    175175
    176176            if (Double.isNaN(deg) && Double.isNaN(min) && Double.isNaN(sec))
    177                 throw new IllegalArgumentException();
     177                throw new IllegalArgumentException("deg, min and sec are NaN");
    178178
    179179            value = (Double.isNaN(deg) ? 0 : deg + (Double.isNaN(min) ? 0 : (min / 60)) + (Double.isNaN(sec) ? 0 : (sec / 3600)));
  • trunk/src/org/openstreetmap/josm/tools/Geometry.java

    r7828 r7864  
    329329        CheckParameterUtil.ensureValidCoordinates(p4, "p4");
    330330
    331         if (!p1.isValid()) throw new IllegalArgumentException();
     331        if (!p1.isValid()) throw new IllegalArgumentException(p1+" is invalid");
    332332
    333333        // Basically, the formula from wikipedia is used:
  • trunk/src/org/openstreetmap/josm/tools/ImageResource.java

    r7731 r7864  
    8181    public ImageIcon getImageIcon(Dimension dim) {
    8282        if (dim.width < -1 || dim.width == 0 || dim.height < -1 || dim.height == 0)
    83             throw new IllegalArgumentException();
     83            throw new IllegalArgumentException(dim+" is invalid");
    8484        Image img = imgCache.get(dim);
    8585        if (img != null) {
     
    123123    public ImageIcon getImageIconBounded(Dimension maxSize) {
    124124        if (maxSize.width < -1 || maxSize.width == 0 || maxSize.height < -1 || maxSize.height == 0)
    125             throw new IllegalArgumentException();
     125            throw new IllegalArgumentException(maxSize+" is invalid");
    126126        float realWidth;
    127127        float realHeight;
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r7835 r7864  
    189189    public static int mod(int a, int n) {
    190190        if (n <= 0)
    191             throw new IllegalArgumentException();
     191            throw new IllegalArgumentException("n must be <= 0 but is "+n);
    192192        int res = a % n;
    193193        if (res < 0) {
     
    206206     */
    207207    public static String join(String sep, Collection<?> values) {
    208         if (sep == null)
    209             throw new IllegalArgumentException();
     208        CheckParameterUtil.ensureParameterNotNull(sep, "sep");
    210209        if (values == null)
    211210            return null;
Note: See TracChangeset for help on using the changeset viewer.