Ticket #25017: #25017.patch

File #25017.patch, 29.5 KB (added by DanProgs <Abenteurer.2901@…>, 22 minutes ago)
  • src/org/openstreetmap/josm/data/validation/tests/TagChecker.java

    ### Eclipse Workspace Patch 1.0
    #P josm
    diff --git src/org/openstreetmap/josm/data/validation/tests/TagChecker.java src/org/openstreetmap/josm/data/validation/tests/TagChecker.java
    index 7b501c6..8433975 100644
     
    261261     */
    262262    private static void analysePresets() {
    263263        for (String key : TaggingPresets.getPresetKeys()) {
    264             if (isKeyIgnored(key))
     264            if (isKeyIgnored(key)) {
    265265                continue;
    266             Set<String> values = TaggingPresets.getPresetValues(key);
    267             boolean allNumerical = !Utils.isEmpty(values)
     266            }
     267            final Set<String> values = TaggingPresets.getPresetValues(key);
     268            final boolean allNumerical = !Utils.isEmpty(values)
    268269                    && values.stream().allMatch(TagChecker::isNum);
    269270            if (allNumerical) {
    270271                ignoreForLevenshtein.add(key);
    … …  
    291292        presetIndex.clear();
    292293        ignoreForOuterMPSameTagCheck.clear();
    293294
    294         StringBuilder errorSources = new StringBuilder();
     295        final StringBuilder errorSources = new StringBuilder();
    295296        for (String source : Config.getPref().getList(PREF_SOURCES, DEFAULT_SOURCES)) {
    296297            try (
    297298                CachedFile cf = new CachedFile(source);
    … …  
    304305            }
    305306        }
    306307
    307         if (errorSources.length() > 0)
     308        if (errorSources.length() > 0) {
    308309            throw new IOException(trn(
    309310                    "Could not access data file:\n{0}",
    310311                    "Could not access data files:\n{0}", errorSources.length(), errorSources));
     312        }
    311313    }
    312314
    313315    private static void parseSource(String source, BufferedReader reader) throws IOException {
    … …  
    337339            } else if (line.charAt(0) == '+') {
    338340                okValue = line.substring(1);
    339341            } else if (line.charAt(0) == '-' && okValue != null) {
    340                 String hk = harmonizeKey(line.substring(1));
     342                final String hk = harmonizeKey(line.substring(1));
    341343                if (!okValue.equals(hk) && harmonizedKeys.put(hk, okValue) != null && Logging.isDebugEnabled()) {
    342344                    Logging.debug("Line was ignored: " + line);
    343345                }
    … …  
    364366            return;
    365367        }
    366368        try {
    367             String key = line.substring(0, 2);
     369            final String key = line.substring(0, 2);
    368370            line = line.substring(2);
    369371
    370372            switch (key) {
    … …  
    379381                ignoreDataEndsWith.add(line);
    380382                break;
    381383            case "K:":
    382                 Tag tag = Tag.ofString(line);
     384                final Tag tag = Tag.ofString(line);
    383385                ignoreDataTag.add(tag);
    384386                oftenUsedTags.put(tag.getKey(), tag.getValue());
    385387                addToKeyDictionary(tag.getKey());
    … …  
    396398    }
    397399
    398400    private static void addToKeyDictionary(String key) {
    399         if (key != null) {
    400             String hk = harmonizeKey(key);
    401             if (!key.equals(hk)) {
    402                 harmonizedKeys.put(hk, key);
    403             }
     401        if (key == null) {
     402            return;
     403        }
     404        final String hk = harmonizeKey(key);
     405        if (!key.equals(hk)) {
     406            harmonizedKeys.put(hk, key);
    404407        }
    405408    }
    406409
    … …  
    410413     */
    411414    public static void initializePresets() {
    412415
    413         if (!Config.getPref().getBoolean(PREF_CHECK_VALUES, true))
     416        if (!Config.getPref().getBoolean(PREF_CHECK_VALUES, true)) {
    414417            return;
     418        }
    415419
    416         Collection<TaggingPreset> presets = TaggingPresets.getTaggingPresets();
    417         if (!presets.isEmpty()) {
    418             initAdditionalPresetsValueData();
    419             for (TaggingPreset p : presets) {
    420                 List<TaggingPresetItem> minData = new ArrayList<>();
    421                 for (TaggingPresetItem i : p.data) {
    422                     if (i instanceof KeyedItem) {
    423                         if (!"none".equals(((KeyedItem) i).match()))
    424                             minData.add(i);
    425                         addPresetValue((KeyedItem) i);
    426                     } else if (i instanceof CheckGroup) {
    427                         for (Check c : ((CheckGroup) i).checks) {
    428                             if (!"none".equals(c.match()))
    429                                 minData.add(c);
    430                             addPresetValue(c);
     420        final Collection<TaggingPreset> presets = TaggingPresets.getTaggingPresets();
     421        if (presets.isEmpty()) {
     422            return;
     423        }
     424        initAdditionalPresetsValueData();
     425        for (TaggingPreset p : presets) {
     426            final List<TaggingPresetItem> minData = new ArrayList<>();
     427            for (TaggingPresetItem i : p.data) {
     428                if (i instanceof KeyedItem) {
     429                    if (!"none".equals(((KeyedItem) i).match())) {
     430                        minData.add(i);
     431                    }
     432                    addPresetValue((KeyedItem) i);
     433                } else if (i instanceof CheckGroup) {
     434                    for (Check c : ((CheckGroup) i).checks) {
     435                        if (!"none".equals(c.match())) {
     436                            minData.add(c);
    431437                        }
     438                        addPresetValue(c);
    432439                    }
    433440                }
    434                 if (!minData.isEmpty()) {
    435                     presetIndex.put(p, minData);
    436                 }
     441            }
     442            if (!minData.isEmpty()) {
     443                presetIndex.put(p, minData);
    437444            }
    438445        }
    439446    }
    … …  
    514521     * @return {@code true} if the current unicode block is very unusual for the given key
    515522     */
    516523    private static boolean isUnusualUnicodeBlock(String key, int c) {
    517         UnicodeBlock b = UnicodeBlock.of(c);
     524        final UnicodeBlock b = UnicodeBlock.of(c);
    518525        return isUnusualPhoneticUse(key, b, c) || isUnusualBmpUse(b) || isUnusualSmpUse(b);
    519526    }
    520527
    … …  
    579586        if (TaggingPresets.isKeyInPresets(key)) {
    580587            return TaggingPresets.getPresetValues(key);
    581588        }
    582         if (additionalPresetsValueData.contains(key))
     589        if (additionalPresetsValueData.contains(key)) {
    583590            return Collections.emptySet();
     591        }
    584592        // null means key is not known
    585593        return null;
    586594    }
    … …  
    625633     * @since 9023
    626634     */
    627635    public static boolean isTagIgnored(String key, String value) {
    628         if (isKeyIgnored(key))
     636        if (isKeyIgnored(key)) {
    629637            return true;
     638        }
    630639        final Set<String> values = getPresetValues(key);
    631         if (values != null && values.isEmpty())
     640        if (values != null && values.isEmpty()) {
    632641            return true;
     642        }
    633643        if (!isTagInPresets(key, value)) {
    634644            return ignoreDataTag.stream()
    635645                    .anyMatch(a -> key.equals(a.getKey()) && value.equals(a.getValue()));
    … …  
    643653     */
    644654    @Override
    645655    public void check(OsmPrimitive p) {
    646         if (!p.isTagged())
     656        if (!p.isTagged()) {
    647657            return;
     658        }
    648659
    649660        // Just a collection to know if a primitive has been already marked with error
    650         MultiMap<OsmPrimitive, String> withErrors = new MultiMap<>();
     661        final MultiMap<OsmPrimitive, String> withErrors = new MultiMap<>();
    651662
    652663        for (Entry<String, String> prop : p.getKeys().entrySet()) {
    653             String s = marktr("Tag ''{0}'' invalid.");
    654             String key = prop.getKey();
    655             String value = prop.getValue();
     664            final String s = marktr("Tag ''{0}'' invalid.");
     665            final String key = prop.getKey();
     666            final String value = prop.getValue();
    656667
    657668            if (checkKeys) {
    658669                checkSingleTagKeySimple(withErrors, p, s, key);
    … …  
    675686        }
    676687
    677688        final Collection<TaggingPreset> matchingPresets;
    678         TagMap tags;
     689        final TagMap tags;
    679690        if (checkPresetsTypes || checkRegions) {
    680691            tags = p.getKeys();
    681692            matchingPresets = presetIndex.entrySet().stream()
    … …  
    703714     * @param tags Tags from the primitive to check
    704715     */
    705716    private void checkPresetsTypes(OsmPrimitive p, Collection<TaggingPreset> matchingPresets, Map<String, String> tags) {
    706         TaggingPresetType presetType = TaggingPresetType.forPrimitive(p);
    707         EnumSet<TaggingPresetType> presetTypes = EnumSet.of(presetType);
     717        final TaggingPresetType presetType = TaggingPresetType.forPrimitive(p);
     718        final EnumSet<TaggingPresetType> presetTypes = EnumSet.of(presetType);
    708719
    709         Collection<TaggingPreset> matchingPresetsOK = matchingPresets.stream().filter(
     720        final Collection<TaggingPreset> matchingPresetsOK = matchingPresets.stream().filter(
    710721                tp -> tp.typeMatches(presetTypes)).collect(Collectors.toList());
    711         Collection<TaggingPreset> matchingPresetsKO = matchingPresets.stream().filter(
     722        final Collection<TaggingPreset> matchingPresetsKO = matchingPresets.stream().filter(
    712723                tp -> !tp.typeMatches(presetTypes)).collect(Collectors.toList());
    713724
    714725        for (TaggingPreset tp : matchingPresetsKO) {
    715726            // Potential error, unless matching tags are all known by a supported preset
    716             Map<String, String> matchingTags = tp.data.stream()
     727            final Map<String, String> matchingTags = tp.data.stream()
    717728                    .filter(i -> Boolean.TRUE.equals(i.matches(tags)))
    718729                    .filter(KeyedItem.class::isInstance).map(i -> ((KeyedItem) i).key)
    719730                    .collect(Collectors.toMap(k -> k, tags::get, (o, n) -> n));
    … …  
    737748     * @param matchingPresets The presets to check against
    738749     */
    739750    private void checkRegions(OsmPrimitive p, Collection<TaggingPreset> matchingPresets) {
    740         LatLon center;
     751        final LatLon center;
    741752        if (p instanceof Node) {
    742753            center = ((Node) p).getCoor();
    743754        } else {
    … …  
    809820     */
    810821    private void tagCheckReal(TaggingPreset preset, OsmPrimitive p, LatLon center, RegionSpecific data) {
    811822        // First, check if we aren't in the region for the tag
    812         if (latLonInRegions(center, data.regions()) == data.exclude_regions()
     823        if (!(latLonInRegions(center, data.regions()) == data.exclude_regions()
    813824                // Check to ensure that no nodes are in the region if the center is not in the region
    814                 && !primitiveInRegions(p, data.regions(), data.exclude_regions())) {
    815             final String key;
    816             final String value;
    817             if (data instanceof PresetListEntry) {
    818                 key = ((PresetListEntry) data).cms.key;
    819                 value = ((PresetListEntry) data).value;
    820             } else if (data instanceof KeyedItem) {
    821                 key = ((KeyedItem) data).key;
    822                 if (data instanceof Key) {
    823                     value = ((Key) data).value;
    824                 } else {
    825                     value = null;
    826                 }
     825                && !primitiveInRegions(p, data.regions(), data.exclude_regions()))) {
     826            return;
     827        }
     828        final String key;
     829        final String value;
     830        if (data instanceof PresetListEntry) {
     831            key = ((PresetListEntry) data).cms.key;
     832            value = ((PresetListEntry) data).value;
     833        } else if (data instanceof KeyedItem) {
     834            key = ((KeyedItem) data).key;
     835            if (data instanceof Key) {
     836                value = ((Key) data).value;
    827837            } else {
    828                 throw new JosmRuntimeException("Unknown implementor for RegionSpecific");
     838                value = null;
    829839            }
    830             if (p.hasTag(key) && (value == null || value.equals(p.get(key)))) {
    831                 final TestError.Builder builder = TestError.builder(this, Severity.WARNING, INVALID_REGION)
    832                         .primitives(p);
    833                 if (value == null) {
    834                     builder.message(tr("Key from a preset is invalid in this region"),
    835                             marktr("Preset {0} should not have the key {1}"),
    836                             preset.getLocaleName(), key);
    837                 } else {
    838                     builder.message(tr("Value from a preset is invalid in this region"),
    839                             marktr("Preset {0} should not have the tag {1}={2}"),
    840                             preset.getLocaleName(), key, value);
    841                 }
    842                 errors.add(builder.build());
     840        } else {
     841            throw new JosmRuntimeException("Unknown implementor for RegionSpecific");
     842        }
     843        if (p.hasTag(key) && (value == null || value.equals(p.get(key)))) {
     844            final TestError.Builder builder = TestError.builder(this, Severity.WARNING, INVALID_REGION)
     845                    .primitives(p);
     846            if (value == null) {
     847                builder.message(tr("Key from a preset is invalid in this region"),
     848                        marktr("Preset {0} should not have the key {1}"),
     849                        preset.getLocaleName(), key);
     850            } else {
     851                builder.message(tr("Value from a preset is invalid in this region"),
     852                        marktr("Preset {0} should not have the tag {1}={2}"),
     853                        preset.getLocaleName(), key, value);
    843854            }
     855            errors.add(builder.build());
    844856        }
    845857    }
    846858
    … …  
    893905
    894906    private void checkMultipolygonTags(OsmPrimitive p) {
    895907        if (p.isAnnotated() || p.keys()
    896                 .anyMatch(k -> k.matches("^(abandoned|construction|demolished|disused|planned|razed|removed|was).*")))
     908                .anyMatch(k -> k.matches("^(abandoned|construction|demolished|disused|planned|razed|removed|was).*"))) {
    897909            return;
     910        }
    898911
    899912        checkOuterWaysOfRelation((Relation) p);
    900913
    901         if (hasAcceptedPrimaryTagForMultipolygon(p))
     914        if (hasAcceptedPrimaryTagForMultipolygon(p)) {
    902915            return;
     916        }
    903917        TestError.Builder builder = null;
    904918        if (p.hasKey("surface")) {
    905919            // accept often used tag surface=* as area tag
    906920            builder = TestError.builder(this, Severity.OTHER, MULTIPOLYGON_INCOMPLETE)
    907921                    .message(tr(MULTIPOLYGON_TAGS), marktr("only {0} tag"), "surface");
    908922        } else {
    909             Map<String, String> filteredTags = p.getInterestingTags();
     923            final Map<String, String> filteredTags = p.getInterestingTags();
    910924            filteredTags.remove("type");
    911925            NO_AREA_KEYS.forEach(filteredTags::remove);
    912926            filteredTags.keySet().removeIf(key -> !key.matches("[a-z0-9:_]+"));
    … …  
    931945     */
    932946    private void checkOuterWaysOfRelation(Relation rel) {
    933947        for (Entry<String, String> tag : rel.getInterestingTags().entrySet()) {
    934             if (ignoreForOuterMPSameTagCheck.contains(tag.getKey()))
     948            if (ignoreForOuterMPSameTagCheck.contains(tag.getKey())) {
    935949                continue;
     950            }
    936951
    937             Set<Way> sameOuters = rel.getMembers().stream()
     952            final Set<Way> sameOuters = rel.getMembers().stream()
    938953                    .filter(rm -> rm.isWay() && rm.getWay().isArea() && "outer".equals(rm.getRole())
    939954                            && tag.getValue().equals(rm.getWay().get(tag.getKey())))
    940955                    .map(RelationMember::getWay).collect(Collectors.toSet());
    941956            if (!sameOuters.isEmpty()) {
    942                 List<OsmPrimitive> primitives = new ArrayList<>(sameOuters.size() + 1);
     957                final List<OsmPrimitive> primitives = new ArrayList<>(sameOuters.size() + 1);
    943958                primitives.add(rel);
    944959                primitives.addAll(sameOuters);
    945                 Way w = new Way();
     960                final Way w = new Way();
    946961                w.put(tag.getKey(), tag.getValue());
    947962                if (hasAcceptedPrimaryTagForMultipolygon(w)) {
    948963                    errors.add(TestError.builder(this, Severity.WARNING, MULTIPOLYGON_SAME_TAG_ON_OUTER)
    … …  
    976991                        "speed_camera", "traffic_mirror", "trailhead", "turning_circle", "turning_loop", "toll_gantry")
    977992                || p.hasTagDifferent("tourism", "attraction", "artwork")
    978993                || p.hasTagDifferent("leisure", "picnic_table", "slipway", "firepit")
    979                 || p.hasTagDifferent("historic", "wayside_cross", "milestone"))
     994                || p.hasTagDifferent("historic", "wayside_cross", "milestone")) {
    980995            return true;
     996        }
    981997        if (p.hasTag("barrier", "hedge", "retaining_wall")
    982998                || p.hasTag("public_transport", "platform", "station")
    983999                || p.hasTag("railway", "platform")
    … …  
    9861002                || p.hasTag("power", "substation", "generator", "plant", "switchgear", "converter", "sub_station")
    9871003                || p.hasTag(SEAMARK_TYPE, "harbour", "fairway", "anchorage", "landmark", "berth", "harbour_basin",
    9881004                        "separation_zone")
    989                 || (p.get(SEAMARK_TYPE) != null && p.get(SEAMARK_TYPE).matches(".*\\_(area|zone)$")))
     1005                || (p.get(SEAMARK_TYPE) != null && p.get(SEAMARK_TYPE).matches(".*\\_(area|zone)$"))) {
    9901006            return true;
     1007        }
    9911008        return p.hasTag("harbour", OsmUtils.TRUE_VALUE)
    9921009                || p.hasTag("flood_prone", OsmUtils.TRUE_VALUE)
    9931010                || p.hasTag("bridge", OsmUtils.TRUE_VALUE)
    … …  
    9961013    }
    9971014
    9981015    private void checkSingleTagValueSimple(MultiMap<OsmPrimitive, String> withErrors, OsmPrimitive p, String s, String key, String value) {
    999         if (!checkValues || value == null)
     1016        if (!checkValues || value == null) {
    10001017            return;
     1018        }
    10011019        if (containsUnwantedNonPrintingControlCharacter(value) && !withErrors.contains(p, "ICV")) {
    10021020            errors.add(TestError.builder(this, Severity.WARNING, LOW_CHAR_VALUE)
    10031021                    .message(tr("Tag value contains non-printing (usually invisible) character"), s, key)
    … …  
    10451063                    .build());
    10461064            withErrors.put(p, errTypeSpace);
    10471065        }
    1048         if (includeOtherSeverity && !value.equals(Entities.unescape(value)) && !withErrors.contains(p, "HTML")) {
    1049             errors.add(TestError.builder(this, Severity.OTHER, INVALID_HTML)
    1050                     .message(tr("Property values contain HTML entity"), s, key)
    1051                     .primitives(p)
    1052                     .build());
    1053             withErrors.put(p, "HTML");
     1066        if (!(includeOtherSeverity && !value.equals(Entities.unescape(value)) && !withErrors.contains(p, "HTML"))) {
     1067            return;
    10541068        }
     1069        errors.add(TestError.builder(this, Severity.OTHER, INVALID_HTML)
     1070                .message(tr("Property values contain HTML entity"), s, key)
     1071                .primitives(p)
     1072                .build());
     1073        withErrors.put(p, "HTML");
    10551074    }
    10561075
    10571076    private void checkSingleTagKeySimple(MultiMap<OsmPrimitive, String> withErrors, OsmPrimitive p, String s, String key) {
    1058         if (!checkKeys || key == null)
     1077        if (!checkKeys || key == null) {
    10591078            return;
     1079        }
    10601080        if (containsUnwantedNonPrintingControlCharacter(key) && !withErrors.contains(p, "ICK")) {
    10611081            errors.add(TestError.builder(this, Severity.WARNING, LOW_CHAR_KEY)
    10621082                    .message(tr("Tag key contains non-printing character"), s, key)
    … …  
    10731093                    .build());
    10741094            withErrors.put(p, "LK");
    10751095        }
    1076         if (key.indexOf(' ') >= 0 && !withErrors.contains(p, "IPK")) {
    1077             errors.add(TestError.builder(this, Severity.WARNING, INVALID_KEY_SPACE)
    1078                     .message(tr("Invalid white space in property key"), s, key)
    1079                     .primitives(p)
    1080                     .build());
    1081             withErrors.put(p, "IPK");
     1096        if (!(key.indexOf(' ') >= 0 && !withErrors.contains(p, "IPK"))) {
     1097            return;
    10821098        }
     1099        errors.add(TestError.builder(this, Severity.WARNING, INVALID_KEY_SPACE)
     1100                .message(tr("Invalid white space in property key"), s, key)
     1101                .primitives(p)
     1102                .build());
     1103        withErrors.put(p, "IPK");
    10831104    }
    10841105
    10851106    private void checkSingleTagComplex(MultiMap<OsmPrimitive, String> withErrors, OsmPrimitive p, String key, String value) {
    1086         if (!checkValues || key == null || Utils.isEmpty(value))
     1107        if (!checkValues || key == null || Utils.isEmpty(value)) {
    10871108            return;
     1109        }
    10881110        if (additionalPresetsValueData != null && !isTagIgnored(key, value)) {
    10891111            if (!TaggingPresets.isKeyInPresets(key)) {
    10901112                spellCheckKey(withErrors, p, key);
    … …  
    11051127    }
    11061128
    11071129    private void spellCheckKey(MultiMap<OsmPrimitive, String> withErrors, OsmPrimitive p, String key) {
    1108         String prettifiedKey = harmonizeKey(key);
     1130        final String prettifiedKey = harmonizeKey(key);
    11091131        String fixedKey;
    11101132        if (ignoreDataEquals.contains(prettifiedKey)) {
    11111133            fixedKey = prettifiedKey;
    … …  
    11401162    private void tryGuess(OsmPrimitive p, String key, String value, MultiMap<OsmPrimitive, String> withErrors) {
    11411163        // try to fix common typos and check again if value is still unknown
    11421164        final String harmonizedValue = harmonizeValue(value);
    1143         if (Utils.isEmpty(harmonizedValue))
     1165        if (Utils.isEmpty(harmonizedValue)) {
    11441166            return;
     1167        }
    11451168        String fixedValue;
    1146         List<Set<String>> sets = new ArrayList<>();
    1147         Set<String> presetValues = getPresetValues(key);
    1148         if (presetValues != null)
     1169        final List<Set<String>> sets = new ArrayList<>();
     1170        final Set<String> presetValues = getPresetValues(key);
     1171        if (presetValues != null) {
    11491172            sets.add(presetValues);
    1150         Set<String> usedValues = oftenUsedTags.get(key);
    1151         if (usedValues != null)
     1173        }
     1174        final Set<String> usedValues = oftenUsedTags.get(key);
     1175        if (usedValues != null) {
    11521176            sets.add(usedValues);
     1177        }
    11531178        fixedValue = sets.stream().anyMatch(possibleValues -> possibleValues.contains(harmonizedValue))
    11541179                ? harmonizedValue : null;
    11551180        if (fixedValue == null && !ignoreForLevenshtein.contains(key)) {
    11561181            int maxPresetValueLen = 0;
    1157             List<String> fixVals = new ArrayList<>();
     1182            final List<String> fixVals = new ArrayList<>();
    11581183            // use Levenshtein distance to find typical typos
    11591184            int minDist = MAX_LEVENSHTEIN_DISTANCE + 1;
    11601185            for (Set<String> possibleValues: sets) {
    11611186                for (String possibleVal : possibleValues) {
    1162                     if (possibleVal.isEmpty())
     1187                    if (possibleVal.isEmpty()) {
    11631188                        continue;
     1189                    }
    11641190                    maxPresetValueLen = Math.max(maxPresetValueLen, possibleVal.length());
    11651191                    if (harmonizedValue.length() < 3 && possibleVal.length() >= harmonizedValue.length() + MAX_LEVENSHTEIN_DISTANCE) {
    11661192                        // don't suggest fix value when given value is short and lengths are too different
    11671193                        // for example surface=u would result in surface=mud
    11681194                        continue;
    11691195                    }
    1170                     int dist = Utils.getLevenshteinDistance(possibleVal, harmonizedValue);
     1196                    final int dist = Utils.getLevenshteinDistance(possibleVal, harmonizedValue);
    11711197                    if (dist >= harmonizedValue.length()) {
    11721198                        // short value, all characters are different. Don't warn, might say Value '10' for key 'fee' looks like 'no'.
    11731199                        continue;
    … …  
    11831209            }
    11841210            if (minDist <= MAX_LEVENSHTEIN_DISTANCE && maxPresetValueLen > MAX_LEVENSHTEIN_DISTANCE
    11851211                    && !fixVals.isEmpty()
     1212                    && harmonizedValue != null
    11861213                    && (harmonizedValue.length() > 3 || minDist < MAX_LEVENSHTEIN_DISTANCE)) {
    11871214                filterDeprecatedTags(p, key, fixVals);
    11881215                if (!fixVals.isEmpty()) {
    … …  
    12241251
    12251252    // see #19180
    12261253    private void filterDeprecatedTags(OsmPrimitive p, String key, List<String> fixVals) {
    1227         if (fixVals.isEmpty() || deprecatedChecker == null)
     1254        if (fixVals.isEmpty() || deprecatedChecker == null) {
    12281255            return;
     1256        }
    12291257
    1230         int unchangedDeprecated = countDeprecated(p);
     1258        final int unchangedDeprecated = countDeprecated(p);
    12311259
    12321260        // see #19895: create deep clone. This complex method works even with locked files
    1233         MergeSourceBuildingVisitor builder = new MergeSourceBuildingVisitor(p.getDataSet());
     1261        final MergeSourceBuildingVisitor builder = new MergeSourceBuildingVisitor(p.getDataSet());
    12341262        p.accept(builder);
    1235         DataSet clonedDs = builder.build();
    1236         OsmPrimitive clone = clonedDs.getPrimitiveById(p.getPrimitiveId());
     1263        final DataSet clonedDs = builder.build();
     1264        final OsmPrimitive clone = clonedDs.getPrimitiveById(p.getPrimitiveId());
    12371265
    1238         Iterator<String> iter = fixVals.iterator();
     1266        final Iterator<String> iter = fixVals.iterator();
    12391267        while (iter.hasNext()) {
    12401268            clone.put(key, iter.next());
    1241             if (countDeprecated(clone) > unchangedDeprecated)
     1269            if (countDeprecated(clone) > unchangedDeprecated) {
    12421270                iter.remove();
     1271            }
    12431272        }
    12441273    }
    12451274
    12461275    private int countDeprecated(OsmPrimitive p) {
    1247         if (deprecatedChecker == null)
     1276        if (deprecatedChecker == null) {
    12481277            return 0;
     1278        }
    12491279        deprecatedChecker.getErrors().clear();
    12501280        deprecatedChecker.visit(Collections.singleton(p), url -> url.endsWith("deprecated.mapcss"));
    12511281        return deprecatedChecker.getErrors().size();
    … …  
    13261356
    13271357    @Override
    13281358    public void addGui(JPanel testPanel) {
    1329         GBC a = GBC.eol();
     1359        final GBC a = GBC.eol();
    13301360        a.anchor = GridBagConstraints.LINE_END;
    13311361
    13321362        testPanel.add(new JLabel(name+" :"), GBC.eol().insets(3, 0, 0, 0));
    … …  
    13531383        testPanel.add(new JLabel(tr("Data sources ({0})", "*.cfg")), GBC.eol().insets(23, 0, 0, 0));
    13541384        testPanel.add(sourcesList, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(23, 0, 0, 0));
    13551385
    1356         ActionListener disableCheckActionListener = e -> handlePrefEnable();
     1386        final ActionListener disableCheckActionListener = e -> handlePrefEnable();
    13571387        prefCheckKeys.addActionListener(disableCheckActionListener);
    13581388        prefCheckKeysBeforeUpload.addActionListener(disableCheckActionListener);
    13591389        prefCheckComplex.addActionListener(disableCheckActionListener);
    … …  
    13981428     * Enables/disables the source list field
    13991429     */
    14001430    public void handlePrefEnable() {
    1401         boolean selected = prefCheckKeys.isSelected() || prefCheckKeysBeforeUpload.isSelected()
     1431        final boolean selected = prefCheckKeys.isSelected() || prefCheckKeysBeforeUpload.isSelected()
    14021432                || prefCheckComplex.isSelected() || prefCheckComplexBeforeUpload.isSelected();
    14031433        sourcesList.setEnabled(selected);
    14041434    }
    … …  
    14261456
    14271457    @Override
    14281458    public Command fixError(TestError testError) {
    1429         List<Command> commands = new ArrayList<>(50);
     1459        final List<Command> commands = new ArrayList<>(50);
    14301460
    1431         Collection<? extends OsmPrimitive> primitives = testError.getPrimitives();
     1461        final Collection<? extends OsmPrimitive> primitives = testError.getPrimitives();
    14321462        for (OsmPrimitive p : primitives) {
    1433             Map<String, String> tags = p.getKeys();
     1463            final Map<String, String> tags = p.getKeys();
    14341464            if (tags.isEmpty()) {
    14351465                continue;
    14361466            }
    14371467
    14381468            for (Entry<String, String> prop: tags.entrySet()) {
    1439                 String key = prop.getKey();
    1440                 String value = prop.getValue();
     1469                final String key = prop.getKey();
     1470                final String value = prop.getValue();
    14411471                if (Utils.isStripEmpty(value)) {
    14421472                    commands.add(new ChangePropertyCommand(p, key, null));
    14431473                } else if (value.startsWith(" ") || value.endsWith(" ") || value.contains("  ")) {
    … …  
    14451475                } else if (key.startsWith(" ") || key.endsWith(" ") || key.contains("  ")) {
    14461476                    commands.add(new ChangePropertyKeyCommand(p, key, Utils.removeWhiteSpaces(key)));
    14471477                } else {
    1448                     String evalue = Entities.unescape(value);
     1478                    final String evalue = Entities.unescape(value);
    14491479                    if (!evalue.equals(value)) {
    14501480                        commands.add(new ChangePropertyCommand(p, key, evalue));
    14511481                    }
    … …  
    14531483            }
    14541484        }
    14551485
    1456         if (commands.isEmpty())
     1486        if (commands.isEmpty()) {
    14571487            return null;
    1458         if (commands.size() == 1)
     1488        }
     1489        if (commands.size() == 1) {
    14591490            return commands.get(0);
     1491        }
    14601492
    14611493        return new SequenceCommand(tr("Fix tags"), commands);
    14621494    }
    14631495
    14641496    @Override
    14651497    public boolean isFixable(TestError testError) {
    1466         if (testError.getTester() instanceof TagChecker) {
    1467             int code = testError.getCode();
    1468             return code == EMPTY_VALUES || code == INVALID_SPACE ||
    1469                    code == INVALID_KEY_SPACE || code == INVALID_HTML ||
    1470                    code == MULTIPLE_SPACES;
     1498        if (!(testError.getTester() instanceof TagChecker)) {
     1499            return false;
    14711500        }
    1472 
    1473         return false;
     1501        final int code = testError.getCode();
     1502        return code == EMPTY_VALUES || code == INVALID_SPACE ||
     1503               code == INVALID_KEY_SPACE || code == INVALID_HTML ||
     1504               code == MULTIPLE_SPACES;
    14741505    }
    14751506
    14761507    @Override