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

Remove redundant null check from String.getBytes(String charsetName)

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 18
    • None
    • core-libs
    • b14

      Current implementation looks like this:

      public byte[] getBytes(String charsetName)
              throws UnsupportedEncodingException {
          if (charsetName == null) throw new NullPointerException();
          return encode(lookupCharset(charsetName), coder(), value);
      }

      Null check seems to be redundant here because the same check fo 'charsetName' is done within String.lookupCharset(String):

      private static Charset lookupCharset(String csn) throws UnsupportedEncodingException {
          Objects.requireNonNull(csn);
          try {
              return Charset.forName(csn);
          } catch (UnsupportedCharsetException | IllegalCharsetNameException x) {
              throw new UnsupportedEncodingException(csn);
          }
      }

            stsypanov Sergey Tsypanov
            stsypanov Sergey Tsypanov
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: