Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8288329

Avoid redundant TreeMap.containsKey call in PolicyParser.read

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P5 P5
    • 20
    • None
    • security-libs

      There is a field 'Map<String, DomainEntry> domainEntries' in sun.security.provider.PolicyParser class. It's filled in 'read' method with non-null values only. In read method there is redundant 'containsKey' check:

          if (!domainEntries.containsKey(domainName)) {
              domainEntries.put(domainName, de);
          } else {
              LocalizedMessage localizedMsg = new LocalizedMessage(
                  "duplicate.keystore.domain.name");
              Object[] source = {domainName};
              String msg = "duplicate keystore domain name: " +
                           domainName;
              throw new ParsingException(msg, localizedMsg, source);
          }

      Instead of pair TreeMap.containsKey/TreeMap.put method calls, we can use single call TreeMap.putIfAbsent and check result for nullness.

            aturbanov Andrey Turbanov
            aturbanov Andrey Turbanov
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: