RFR: 8176188: jdk/internal/misc/JavaLangAccess/NewUnsafeString.java failing since 9-b93

Claes Redestad claes.redestad at oracle.com
Sun Dec 3 19:53:01 UTC 2017


the compact strings JEP changed semantics of the package-private 
String(char[], boolean)
constructor to do the same as the public String(char[]) constructor.

Previously the former was used in trusted, internal code to avoid 
copying the given char[],
but since the char[] now has to be converted to a byte[] that 
optimization is no longer
possible via this method[1], and tests that checked that the returned 
string shared the
given char[] naturally stopped working.

To fix this bug I propose the following clean-up:
- change all uses of JavaLangAccess.newUnsafeString(char[]) to new 
- remove the package-private String(char[], boolean) constructor
- remove the newUnsafeString from JavaLangAccess
- remove the now unnecessary NewUnsafeString test

Patch: http://cr.openjdk.java.net/~redestad/8176188/open.00/
Bug: https://bugs.openjdk.java.net/browse/JDK-8176188



[1] For some of the usages here we could improve somewhat by exposingthe 
String(byte[], byte)
constructor, but I think that's out of scope here and I think we'd best 
avoid leaking the
coder byte implementation detail outside of java.lang.

More information about the core-libs-dev mailing list