Changeset 11261 in josm


Ignore:
Timestamp:
2016-11-16T13:04:17+01:00 (6 months ago)
Author:
simon04
Message:

fix #13985 - Freezes when creating a layer named "Data Layer "

Location:
trunk
Files:
2 edited

Legend:

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

    r11177 r11261  
    357357        data.addDataSetListener(MultipolygonCache.getInstance());
    358358        DataSet.addSelectionListener(this);
    359         if (name != null && name.startsWith(createLayerName(""))) {
     359        if (name != null && name.startsWith(createLayerName(""))
     360                && Character.isDigit((name.substring(createLayerName("").length()) + "XX" /*avoid StringIndexOutOfBoundsException*/).charAt(1))) {
    360361            while (AlphanumComparator.getInstance().compare(createLayerName(dataLayerCounter), name) < 0) {
    361                 dataLayerCounter.incrementAndGet();
     362                final int i = dataLayerCounter.incrementAndGet();
     363                if (i > 1_000_000) {
     364                    break; // to avoid looping in unforeseen case
     365                }
    362366            }
    363367        }
  • trunk/test/unit/org/openstreetmap/josm/gui/layer/OsmDataLayerTest.java

    r11224 r11261  
    259259        assertEquals("Data Layer 148", layer2.getName());
    260260    }
     261
     262    @Test
     263    public void testLayerUnnumberedName() {
     264        final OsmDataLayer layer = new OsmDataLayer(new DataSet(), "Data Layer ", null);
     265        assertEquals("Data Layer ", layer.getName());
     266    }
     267
     268    /**
     269     * Non-regression test for ticket #13985
     270     */
     271    @Test
     272    public void testLayerNameDoesFinish() {
     273        final OsmDataLayer layer = new OsmDataLayer(new DataSet(), "Data Layer from GeoJSON: foo.geojson", null);
     274        assertEquals("Data Layer from GeoJSON: foo.geojson", layer.getName());
     275    }
    261276}
Note: See TracChangeset for help on using the changeset viewer.