Uploaded image for project: 'HttpComponents HttpClient'
  1. HttpComponents HttpClient
  2. HTTPCLIENT-1260

Javadoc incorrectly states StringBody(String)'s encoding uses the system default.

    XMLWordPrintableJSON

Details

    Description

      (Sorry if this is the wrong component.)

      In the class `org.apache.http.entity.mime.content.StringBody`, there is the following code:

      /**

      • Create a StringBody from the specified text.
      • The mime type is set to "text/plain".
      • The hosts default charset is used.
        *
      • @param text to be used for the body, not {@code null}
        * @throws UnsupportedEncodingException
        * @throws IllegalArgumentException if the {@code text} parameter is null
        */
        public StringBody(final String text) throws UnsupportedEncodingException { this(text, "text/plain", null); }

        Note that it says "The hosts [sic] default charset is used.". This is incorrect. The code always uses US-ASCII no matter what the host's default charset is (e.g. on Android it is UTF-8).

        Quite annoying! It should read:

        /**
        * Create a StringBody from the specified text.
        * The mime type is set to "text/plain".
        * The charset is set to US-ASCII.
        *
        * @param text to be used for the body, not {@code null}
      • @throws UnsupportedEncodingException
      • @throws IllegalArgumentException if the {@code text}

        parameter is null
        */
        public StringBody(final String text) throws UnsupportedEncodingException

        { this(text, "text/plain", null); }

      I'd appreciate it if you could fix this, so future developers won't have the frustration of working out why their non-ascii characters are all being changed to question marks.

      Attachments

        Activity

          People

            Unassigned Unassigned
            timmmm Tim
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 5m
                5m
                Remaining:
                Remaining Estimate - 5m
                5m
                Logged:
                Time Spent - Not Specified
                Not Specified