Changeset 17564 in josm


Ignore:
Timestamp:
2021-03-15T13:53:05+01:00 (4 years ago)
Author:
Don-vip
Message:

fix #20594 - add robustness to AutomaticCombine when Integer values cannot be parsed

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/conflict/tags/TagConflictResolutionUtil.java

    r17093 r17564  
    298298        public String resolve(Set<String> values) {
    299299            Set<String> results = instantiateSortedSet();
    300             for (String value: values) {
    301                 String[] parts = value.split(Pattern.quote(separator), -1);
    302                 results.addAll(Arrays.asList(parts));
     300            String pattern = Pattern.quote(separator);
     301            try {
     302                for (String value: values) {
     303                    results.addAll(Arrays.asList(value.split(pattern, -1)));
     304                }
     305            } catch (NumberFormatException e) {
     306                Logging.error("Unable to parse {0} values in {1} -> {2}", sort, this, e.getMessage());
     307                Logging.debug(e);
     308                results = values;
    303309            }
    304310            return String.join(separator, results);
  • trunk/test/unit/org/openstreetmap/josm/gui/conflict/tags/TagConflictResolutionUtilTest.java

    r17275 r17564  
    55import static org.junit.jupiter.api.Assertions.assertFalse;
    66import static org.junit.jupiter.api.Assertions.assertNull;
     7import static org.junit.jupiter.api.Assertions.assertThrows;
    78import static org.junit.jupiter.api.Assertions.assertTrue;
    8 import static org.junit.jupiter.api.Assertions.assertThrows;
    99
    1010import java.util.Arrays;
     
    213213        void testResolve() {
    214214            for (AutomaticCombine resolver: differentlyConstructed(new AutomaticCombine("random", "", true, "|", "String"))) {
    215                 assertEquals(resolver.resolve(newHashSet("value1", "value2")), "value1|value2");
    216                 assertEquals(resolver.resolve(newHashSet("3|1", "4|2|1", "6|05", "3;1")), "05|1|2|3|3;1|4|6");
     215                assertEquals("value1|value2", resolver.resolve(newHashSet("value1", "value2")));
     216                assertEquals("05|1|2|3|3;1|4|6", resolver.resolve(newHashSet("3|1", "4|2|1", "6|05", "3;1")));
    217217            }
    218218
    219219            for (AutomaticCombine resolver: differentlyConstructed(new AutomaticCombine("test[45].*", "", true, ";", "Integer"))) {
    220                 assertEquals(resolver.resolve(newHashSet("1254545;95;24", "25;24;3")), "3;24;25;95;1254545");
     220                assertEquals("3;24;25;95;1254545", resolver.resolve(newHashSet("1254545;95;24", "25;24;3")));
    221221            }
    222222
     
    224224                String resolution = resolver.resolve(newHashSet("3;x;1", "4;x"));
    225225                assertTrue(resolution.equals("3;x;1;4") || resolution.equals("4;x;3;1"));
     226            }
     227
     228            for (AutomaticCombine resolver: differentlyConstructed(new AutomaticCombine("foo", "", true, ";", "Integer"))) {
     229                assertEquals("bar;1;2;3", resolver.resolve(newHashSet("1;2;3", "bar")));
    226230            }
    227231        }
Note: See TracChangeset for help on using the changeset viewer.