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

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Fixed
    • Priority: P4
    • 18
    • Affects Version/s: None
    • Component/s: 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);
          }
      }

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

              Created:
              Updated:
              Resolved: