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

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

    XMLWordPrintable

Details

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

    Description

      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);
          }
      }

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: