Changeset 14640 in josm for trunk/src


Ignore:
Timestamp:
2019-01-04T23:44:59+01:00 (6 years ago)
Author:
simon04
Message:

fix #17169 - Missing MessageFormat arguments in OptionParser

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/OptionParser.java

    r14441 r14640  
    4242    public OptionParser addShortAlias(String optionName, String shortName) {
    4343        if (!shortName.matches("\\w")) {
    44             throw new IllegalArgumentException("Short name " + shortName + " must be one character");
     44            throw new IllegalArgumentException("Short name '" + shortName + "' must be one character");
    4545        }
    4646        if (availableOptions.containsKey("-" + shortName)) {
    47             throw new IllegalArgumentException("Short name " + shortName + " is already used");
     47            throw new IllegalArgumentException("Short name '" + shortName + "' is already used");
    4848        }
    4949        AvailableOption longDefinition = availableOptions.get("--" + optionName);
     
    7070    private void checkOptionName(String optionName) {
    7171        if (!optionName.matches("\\w([\\w-]*\\w)?")) {
    72             throw new IllegalArgumentException("Illegal option name: " + optionName);
     72            throw new IllegalArgumentException("Illegal option name: '" + optionName + "'");
    7373        }
    7474        if (availableOptions.containsKey("--" + optionName)) {
    75             throw new IllegalArgumentException("The option --" + optionName + " is already registered");
     75            throw new IllegalArgumentException("The option '--" + optionName + "' is already registered");
    7676        }
    7777    }
     
    164164                    } else {
    165165                        if (toHandle.isEmpty() || "--".equals(toHandle.getFirst())) {
    166                             throw new OptionParseException(tr("{0}: option ''{1}'' requires an argument", program));
     166                            throw new OptionParseException(tr("{0}: option ''{1}'' requires an argument", program, optionName));
    167167                        }
    168168                        parameter = toHandle.removeFirst();
     
    179179        availableOptions.values().stream().distinct().forEach(def -> {
    180180            long count = options.stream().filter(p -> def.equals(p.option)).count();
     181            String optionName = availableOptions.entrySet().stream()
     182                    .filter(entry -> def.equals(entry.getValue()))
     183                    .map(Entry::getKey)
     184                    .findFirst()
     185                    .orElse("?");
    181186            if (count < def.getRequiredCount().min) {
    182187                // min may be 0 or 1 at the moment
    183                 throw new OptionParseException(tr("{0}: option ''{1}'' is required"));
     188                throw new OptionParseException(tr("{0}: option ''{1}'' is required", program, optionName));
    184189            } else if (count > def.getRequiredCount().max) {
    185190                // max may be 1 or MAX_INT at the moment
    186                 throw new OptionParseException(tr("{0}: option ''{1}'' may not appear multiple times"));
     191                throw new OptionParseException(tr("{0}: option ''{1}'' may not appear multiple times", program, optionName));
    187192            }
    188193        });
     
    222227                return alternatives.get(0);
    223228            } else if (alternatives.size() > 1) {
    224                 throw new OptionParseException(tr("{0}: option ''{1}'' is ambiguous", program));
     229                throw new OptionParseException(tr("{0}: option ''{1}'' is ambiguous", program, optionName));
    225230            }
    226231        }
Note: See TracChangeset for help on using the changeset viewer.