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

Avoid redundant Hashtable.containsKey call in CodeSource.readObject

XMLWordPrintable

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

      Hashtable.containsKey call is unnecessary before following Hashtable.get call. Hashtable allows only null values. It means we can replace containsKey+get with get+null check.

                  if (cfs.containsKey(certType)) {
                      cf = cfs.get(certType);
                  } else {
                      // create new certificate factory
                      ...
                      cfs.put(certType, cf);
                  }

      We can update to:

                  CertificateFactory cf = cfs.get(certType);
                  if (cf == null) {
                      // create new certificate factory
                      ...
                      cfs.put(certType, cf);
                  }

      It's clearer and a bit faster.

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

              Created:
              Updated:
              Resolved: