Merge pull request #26315 from thjaeckle/bugfix/26286

Make copyUSAsciiStrToBytes more robust w.r.t. JDK for Java9+ #26286
This commit is contained in:
Patrik Nordwall 2019-02-07 10:58:15 +01:00 committed by GitHub
commit b3ec17871a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -46,7 +46,7 @@ public final class Unsafe {
public static void copyUSAsciiStrToBytes(String str, byte[] bytes) {
if (isJavaVersion9Plus) {
final byte[] chars = (byte[]) instance.getObject(str, stringValueFieldOffset);
System.arraycopy(chars, 0, bytes, 0, chars.length);
System.arraycopy(chars, 0, bytes, 0, str.length());
} else {
final char[] chars = (char[]) instance.getObject(str, stringValueFieldOffset);
int i = 0;
@ -63,7 +63,7 @@ public final class Unsafe {
if (isJavaVersion9Plus) {
final byte[] chars = (byte[]) instance.getObject(str, stringValueFieldOffset);
while (i < chars.length) {
while (i < str.length()) {
long x = s0 ^ (long)chars[i++]; // Mix character into PRNG state
long y = s1;
@ -76,7 +76,7 @@ public final class Unsafe {
}
} else {
final char[] chars = (char[]) instance.getObject(str, stringValueFieldOffset);
while (i < chars.length) {
while (i < str.length()) {
long x = s0 ^ (long)chars[i++]; // Mix character into PRNG state
long y = s1;