RFR: 8310901: Convert String::newStringNoRepl with Latin-1 to String::newStringLatin1NoRepl

Chen Liang liach at openjdk.org
Mon Jun 26 16:06:02 UTC 2023


On Mon, 26 Jun 2023 15:25:08 GMT, Glavo <duke at openjdk.org> wrote:

> Added a new method `newStringLatin1NoRepl` to the `JavaLangAccess`.
> 
> Reasons:
> 
> * Most use cases of `newStringNoRepl` use `ISO_8859_1` as the charset, creating a new shortcut can make writing shorter;
> * Since all possible values of `byte` are legal Latin-1 characters, `newStringLatin1NoRepl` **will not throw `CharacterCodingException`**, so users can make the compiler happy without using useless try-catch statements.

src/java.base/share/classes/jdk/internal/access/JavaLangAccess.java line 345:

> 343:      *
> 344:      * The caller of this method shall relinquish and transfer the ownership of
> 345:      * the byte array to the callee since the later will not make a copy.

This comment isn't quite right; the byte array is simply trusted/shared, that it should never be changed or modifiable. The caller can freely retain the array (such as in a field) as long as it doesn't change the array.

This is just a copycat of the original newStringNoRepl, which should be fixed; newStringUTF8NoRepl has no such issue.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/14655#discussion_r1242426598



More information about the security-dev mailing list