Changeset 15946 in josm


Ignore:
Timestamp:
2020-02-27T19:52:40+01:00 (3 months ago)
Author:
simon04
Message:

fix #18798, see #14088 - Crash when adding junction=roundabout to a node (patch by taylor.smock)

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelper.java

    r15889 r15946  
    7171import org.openstreetmap.josm.command.SequenceCommand;
    7272import org.openstreetmap.josm.data.UndoRedoHandler;
     73import org.openstreetmap.josm.data.coor.LatLon;
    7374import org.openstreetmap.josm.data.osm.DataSet;
     75import org.openstreetmap.josm.data.osm.INode;
    7476import org.openstreetmap.josm.data.osm.OsmDataManager;
    7577import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    693695            final OsmPrimitive virtual = (osmPrimitiveIterator.hasNext() ? osmPrimitiveIterator.next().getType() : OsmPrimitiveType.NODE)
    694696                    .newInstance(0, false);
     697            if (virtual instanceof INode) {
     698                ((INode) virtual).setCoor(LatLon.ZERO);
     699            }
    695700            virtual.put(key, value);
    696701            final ImageIcon padded = ImageProvider.getPadded(virtual, ImageProvider.ImageSizes.LARGEICON.getImageDimension(),
  • trunk/test/unit/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelperTest.java

    r15927 r15946  
    3737import org.openstreetmap.josm.testutils.JOSMTestRules;
    3838import org.openstreetmap.josm.testutils.mockers.WindowMocker;
     39import org.openstreetmap.josm.tools.RightAndLefthandTraffic;
    3940
    4041import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     
    5051    @Rule
    5152    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    52     public JOSMTestRules test = new JOSMTestRules();
     53    public JOSMTestRules test = new JOSMTestRules().territories().projection();
    5354
    5455    private static TagEditHelper newTagEditHelper() {
     
    124125        assertNotNull(val);
    125126    }
     127
     128    /**
     129     * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/18798>#18798</a>
     130     *
     131     * @throws InvocationTargetException Check logs -- if caused by NPE, a
     132     *                                   regression probably occurred.
     133     * @throws IllegalArgumentException  Check source code
     134     * @throws IllegalAccessException    Check source code
     135     * @throws NoSuchFieldException      Check source code
     136     * @throws SecurityException         Probably shouldn't happen for tests
     137     * @throws NoSuchMethodException     Check source code
     138     */
     139    @Test
     140    public void testTicket18798() throws NoSuchMethodException, SecurityException, IllegalAccessException,
     141            IllegalArgumentException, InvocationTargetException, NoSuchFieldException {
     142        TestUtils.assumeWorkingJMockit();
     143        if (GraphicsEnvironment.isHeadless()) {
     144            new WindowMocker();
     145        }
     146        RightAndLefthandTraffic.initialize();
     147        MapCSSStyleSource css = new MapCSSStyleSource(
     148                "node:righthandtraffic[junction=roundabout] { text: tr(\"Roundabout node\"); }");
     149        css.loadStyleSource();
     150        MapPaintStyles.addStyle(css);
     151        Node node = new Node(LatLon.NORTH_POLE);
     152        DataSet ds = new DataSet(node);
     153        OsmDataManager.getInstance().setActiveDataSet(ds);
     154        MainApplication.getLayerManager().addLayer(new OsmDataLayer(ds, "Test Layer", null));
     155        TagEditHelper helper = newTagEditHelper();
     156        Field sel = TagEditHelper.class.getDeclaredField("sel");
     157        sel.set(helper, Collections.singletonList(node));
     158        AddTagsDialog addTagsDialog = helper.getAddTagsDialog();
     159        Method findIcon = TagEditHelper.AbstractTagsDialog.class.getDeclaredMethod("findIcon", String.class,
     160                String.class);
     161        findIcon.setAccessible(true);
     162        Object val = findIcon.invoke(addTagsDialog, "junction", "roundabout");
     163        assertNotNull(val);
     164    }
    126165}
Note: See TracChangeset for help on using the changeset viewer.