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

java.net.URLDecoder / URLEncoder should accept java.nio.charset.Charset

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • None
    • core-libs
    • x86
    • linux_ubuntu

      A DESCRIPTION OF THE REQUEST :
      Currently URLDecoder has this API:

      static String decode(String s, String enc) throws UnsupportedEncodingException

      Which is unsafe and annoying because of checked Exception which is in most cases useless when used with a fixed String in code.

      Instead, URLDecoder should (additionally) have a method
      static String decode(String s, Charset charset)
      which does not raise a checked Exception.



      JUSTIFICATION :
      This is in line with

      public byte[] getBytes(Charset charset)
      public byte[] getBytes(String charsetName)
                  throws UnsupportedEncodingException

      of java.lang.String

      The equivalent reasoning holds for URLEncoder.encode()

      As a result code written using these classes can be safer against typos ("UFT-8"), and unnecessary try/catch blocks can be eliminated.


            chegar Chris Hegarty
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: