RFR: 8356439: Rename JavaLangAccess::*NoRepl methods [v7]

Chen Liang liach at openjdk.org
Wed Aug 27 23:35:44 UTC 2025


On Mon, 25 Aug 2025 07:46:59 GMT, Volkan Yazici <vyazici at 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:
> 
>  - Improve "sneaky throws"
>  - Improve comment style

Marked as reviewed by liach (Reviewer).

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

> 888: 
> 889:     private static <E extends Exception> byte[] encodeWithEncoder(
> 890:             Charset cs, byte coder, byte[] val, Class<E> exceptionClass)

Since `exceptionClass` is a dummy argument that can't actually control the type of exception thrown by this method, that it being null or not is the only thing that matters, I recommend documenting/commenting about this fact, as this is otherwise potentially confusing. Maybe a name to indicate this nature (I came up with `replacementSwitch` but this is for sure horrible) would help too I guess?

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

PR Review: https://git.openjdk.org/jdk/pull/26413#pullrequestreview-3162113328
PR Review Comment: https://git.openjdk.org/jdk/pull/26413#discussion_r2305538047


More information about the security-dev mailing list