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

Add Charset overloads to URLDecoder and URLEncoder

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE REQUEST :
      URL{En,De}coder have methods that allow you to specify the name of the character set to encode to/from. It would be convenient if these methods also had an override that accepted Charset as well. This is especially true since most of the time these methods will be called with UTF-8, and then you could use StandardCharsets.UTF_8 instead of having to pass in "UTF-8".

      JUSTIFICATION :
      This would get rid of all the boilerplate code to handle the UnsupportedCharSetException, which can normally never occur, as the we are using UTF-8 anyway, which is guaranteed to be supported by the JVM.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      That there are methods:

      URLEncoder:
          public static String encode(String s, java.nio.Charset enc)

      URLDecoder:
          public static String decode(String s, java.nio.Charset enc)

      ACTUAL -
      These methods do not exist.

      ---------- BEGIN SOURCE ----------
      public class Test {
        String s = java.net.URLEncoder.encode("string", java.nio.charset.StandardCharsets.UTF_8);
        String s = java.net.URLDecoder.decode("string", java.nio.charset.StandardCharsets.UTF_8);
      }


      This class should compile, but does not.
      ---------- END SOURCE ----------

            joehw Joe Wang
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: