Fix for https://josm.openstreetmap.de/ticket/10513. Patch was provide by don-vip. Thanks.