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

Pem.decode should cache the Pattern

XMLWordPrintable

      SonarCloud complains we are using the String.replaceAll() method that creates Pattern internally every time:

          /**
           * Decodes a PEM-encoded block.
           *
           * @param input the input string, according to RFC 1421, can only contain
           * characters in the base-64 alphabet and whitespaces.
           * @return the decoded bytes
           */
          public static byte[] decode(String input) {
              byte[] src = input.replaceAll("\\s+", "").
                  getBytes(StandardCharsets.ISO_8859_1);
                  return Base64.getDecoder().decode(src);
          }


      We already have cached Patterns for other cases, we should do the same here.

            shade Aleksey Shipilev
            shade Aleksey Shipilev
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: