On Mon, 26 Jun 2023 15:25:08 GMT, Glavo <d...@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

Reply via email to