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

URLEncoder and URLDecoder classes should use StringBuilder, not StringBuffer

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P5 P5
    • None
    • 6u10
    • core-libs
    • x86
    • windows_vista

      FULL PRODUCT VERSION :
      All versions of JDK SE 1.5/5.0 and 1.6/6.0

      ADDITIONAL OS VERSION INFORMATION :
      N/A, OS-generic

      A DESCRIPTION OF THE PROBLEM :
      The java.net.URLEncoder and URLDecoder classes could still use some performance improvements.

      Particularly, they are using synchronized classes when no synchronization is needed. (The instances are internal to the static encode / decode methods.) Uses of StringBuffer should be replaced with StringBuilder, introduced in Java 1.5.

      URLEncoder also uses CharArrayWriter, which adds additional and unnecessary synchronization. Also, as the length of the input String is provided as a hint to the StringBuffer to prevent unnecessary resizing, the same should be done for the CharArrayWriter (or its replacement).

      The synchronization issues are more applicable to Java 1.5 than 1.6, due to the introduction of the escape analysis in 1.6. However, they should still replaced with non-synchronized versions for good practice and for Java 1.5 users.

      Finally, overloaded methods should be provided that allow the passing-in of existing Charset instances, rather than just a String that is passed to Charset.forName() each time. (Consider when multiple encode/decode calls need to be made sequentially.)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      These classes demonstrate less-than-possible performance always.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      These classes should demonstrate better performance by addressing the items listed in the description.
      ACTUAL -
      These classes demonstrate less-than-possible performance always.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      CUSTOMER SUBMITTED WORKAROUND :
      Using an alternate implementation as a replacement for URLEncoder and URLDecoder.

            Unassigned Unassigned
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: