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

(str) String.getBytes() is dangerous since it allows users to rely on the default encoding

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 6
    • core-libs
    • x86
    • windows_xp

      A DESCRIPTION OF THE REQUEST :
      java.lang.String.getBytes() (and all other methods in Java which rely on the platform default encoding) should be deprecated.

      Instead the user should use java.lang.String.getBytes(String) at which point he can no longer avoid reading up on and understanding character sets and encodings.

      JUSTIFICATION :
      java.lang.String.getBytes() allows people to ignore and remain unaware of character sets and encodings. These people are the most likely to then having to invest vast effort to find the resulting bugs.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Java's standard API should not allow to rely on the default encoding anywhere in this fashion.
      ACTUAL -
      Java's standard API allows to rely on the default encoding in this fashion.

      CUSTOMER SUBMITTED WORKAROUND :
      Use of java.lang.String.getBytes(String).

            Unassigned Unassigned
            tyao Ting-Yun Ingrid Yao (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: