On Thu, 28 Aug 2025 19:25:10 GMT, Volkan Yazici <vyaz...@openjdk.org> wrote:

>> `NoRepl`-suffixed `String` methods denote methods that do not replace 
>> invalid characters, but throw `CharacterCodingException` on encounter. This 
>> behavior cannot easily be derived from the method footprints, has been a 
>> source of confusion for maintainers, and is not uniformly adopted, e.g., 
>> `newStringUTF8NoRepl()` and `getBytesUTF8NoRepl()` does *not* throw `CCE`. 
>> This PR replaces the `NoRepl` suffix with `NoReplacement` in method names 
>> and consistently uses `throws CCE` in method footprints.
>
> Volkan Yazici has updated the pull request incrementally with two additional 
> commits since the last revision:
> 
>  - Rename `NoReplacement` suffix to `OrThrow`
>  - Simplify `encodeWithEncoder` and trim long lines

src/java.base/share/classes/java/lang/String.java line 707:

> 705:      * @throws CharacterCodingException for malformed input or 
> unmappable characters
> 706:      */
> 707:     private static String newStringUTF8OrThrow(byte[] bytes, int offset, 
> int length)

Renaming to the OrThrow suffix is good, that really helps the use-sites, the 
far away ones in particular.

src/java.base/share/classes/java/lang/String.java line 1434:

> 1432:      *           having to declare the exception
> 1433:      */
> 1434:     private static <E extends Exception> byte[] encodeUTF8_UTF16(byte[] 
> val, Class<E> exceptionClass) throws E {

Would it be possible to add a brief method description to this method? It's the 
equivalent of decoding val with the UTF-8 charset, then encoding the result 
with the UTF-16 charset, right?

In passing, if rename exceptionClass to exClass then you'll get get some back 
some of the horizontal space in several areas.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/26413#discussion_r2309311930
PR Review Comment: https://git.openjdk.org/jdk/pull/26413#discussion_r2309310126

Reply via email to