RFR: 8316734: URLEncoder should specify that replacement bytes will be used in case of coding error

Darragh Clarke dclarke at openjdk.org
Tue Nov 21 14:24:07 UTC 2023


On Sun, 19 Nov 2023 14:54:34 GMT, Alan Bateman <alanb at openjdk.org> wrote:

>> Currently the descriptions of `URLEncoder.encode` and `URLDecoder.decode` don't specify their use of replacement bytes or replacement character when they cannot handle a character or sequence of bytes. This is longstanding behavior but needs to be documented.
>> 
>> **Solution**
>> - Added a new line to `URLEncoder.encode` API documentation to document that the charset's replacement bytes are used.
>> 
>> - Also changed `URLDecoder.decode` API documentation to document its use of the charset's replacement character, also changed some wording.
>
> src/java.base/share/classes/java/net/URLDecoder.java line 158:
> 
>> 156:      * If any consecutive well-formed escape sequences cannot
>> 157:      * be decoded as a sequence of characters in the supplied {@code Charset}
>> 158:      * {@linkplain java.nio.charset.CharsetDecoder##cae the replacement character} will be used.
> 
> I think it would be a bit clearer to say that erroneous bytes are replaced with the Charset's replacement value.

Thanks for the suggestion, I just wanted to make sure I was understanding you correctly before committing the change. 

Would it be something like this?

```      
     * Erroneous bytes are replaced with the supplied {@code Charset}'s
     * {@linkplain java.nio.charset.CharsetDecoder##cae replacement value}.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/16709#discussion_r1400676032


More information about the net-dev mailing list