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

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

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 18
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      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

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

                Dates

                Created:
                Updated:
                Resolved: