Changeset 11168 in josm


Ignore:
Timestamp:
2016-10-26T14:02:13+02:00 (8 years ago)
Author:
simon04
Message:

fix #13828 - Fix IAE when adding WMS layer with invalid URL

The fix involves checking the URL when constructing WMSLayer instead when calling getTileSource

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/WMSLayer.java

    r11167 r11168  
    3030import org.openstreetmap.josm.gui.ExtendedDialog;
    3131import org.openstreetmap.josm.gui.layer.imagery.TileSourceDisplaySettings;
     32import org.openstreetmap.josm.tools.CheckParameterUtil;
    3233
    3334/**
     
    6162    public WMSLayer(ImageryInfo info) {
    6263        super(info);
     64        CheckParameterUtil.ensureThat(info.getImageryType() == ImageryType.WMS, "ImageryType is WMS");
     65        CheckParameterUtil.ensureParameterNotNull(info.getUrl(), "info.url");
     66        TemplatedWMSTileSource.checkUrl(info.getUrl());
    6367        this.supportedProjections = new TreeSet<>(info.getServerProjections());
    6468    }
     
    8286    @Override
    8387    protected AbstractWMSTileSource getTileSource() {
    84         if (info.getImageryType() == ImageryType.WMS && info.getUrl() != null) {
    85             TemplatedWMSTileSource.checkUrl(info.getUrl());
    86             AbstractWMSTileSource tileSource = new TemplatedWMSTileSource(info);
    87             info.setAttribution(tileSource);
    88             return tileSource;
    89         }
    90         return null;
     88        AbstractWMSTileSource tileSource = new TemplatedWMSTileSource(info);
     89        info.setAttribution(tileSource);
     90        return tileSource;
    9191    }
    9292
  • trunk/test/unit/org/openstreetmap/josm/gui/layer/WMSLayerTest.java

    r10436 r11168  
    3838        }
    3939    }
     40
     41    /**
     42     * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/13828">Bug #13828</a>.
     43     */
     44    @Test(expected = IllegalArgumentException.class)
     45    public void testTicket13828() {
     46        new WMSLayer(new ImageryInfo("TMS", "http://203.159.29.217/try2/{z}/{x}/{y}.png"));
     47    }
    4048}
Note: See TracChangeset for help on using the changeset viewer.