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

Reviewed-by: psandoz, sherman
This commit is contained in:
Claes Redestad 2017-12-05 14:25:16 +01:00
parent 6351f58092
commit 7759531e5c
9 changed files with 5 additions and 138 deletions

View File

@ -645,19 +645,6 @@ public final class String
this(builder, null);
}
/*
* Package private constructor which shares value array for speed.
* this constructor is always expected to be called with share==true.
* a separate constructor is needed because we already have a public
* String(char[]) constructor that makes a copy of the given char[].
*/
// TBD: this is kept for package internal use (Thread/System),
// should be removed if they all have a byte[] version
String(char[] val, boolean share) {
// assert share : "unshared not supported";
this(val, 0, val.length, null);
}
/**
* Returns the length of this string.
* The length is equal to the number of <a href="Character.html#unicode">Unicode

View File

@ -2109,9 +2109,6 @@ public final class System {
public void registerShutdownHook(int slot, boolean registerShutdownInProgress, Runnable hook) {
Shutdown.add(slot, registerShutdownInProgress, hook);
}
public String newStringUnsafe(char[] chars) {
return new String(chars, true);
}
public Thread newThreadWithAcc(Runnable target, AccessControlContext acc) {
return new Thread(target, acc);
}

View File

@ -24,9 +24,6 @@
*/
package java.util;
import jdk.internal.misc.JavaLangAccess;
import jdk.internal.misc.SharedSecrets;
/**
* {@code StringJoiner} is used to construct a sequence of characters separated
* by a delimiter and optionally starting with a supplied prefix
@ -86,8 +83,6 @@ public final class StringJoiner {
*/
private String emptyValue;
private static final JavaLangAccess jla = SharedSecrets.getJavaLangAccess();
/**
* Constructs a {@code StringJoiner} with no characters in it, with no
* {@code prefix} or {@code suffix}, and a copy of the supplied
@ -189,7 +184,7 @@ public final class StringJoiner {
}
}
k += getChars(suffix, chars, k);
return jla.newStringUnsafe(chars);
return new String(chars);
}
/**
@ -252,7 +247,7 @@ public final class StringJoiner {
elts[i] = null;
} while (++i < size);
size = 1;
elts[0] = jla.newStringUnsafe(chars);
elts[0] = new String(chars);
}
}

View File

@ -123,16 +123,6 @@ public interface JavaLangAccess {
*/
void registerShutdownHook(int slot, boolean registerShutdownInProgress, Runnable hook);
/**
* Returns a new string backed by the provided character array. The
* character array is not copied and must never be modified after the
* String is created, in order to fulfill String's contract.
*
* @param chars the character array to back the string
* @return a newly created string whose content is the character array
*/
String newStringUnsafe(char[] chars);
/**
* Returns a new Thread with the given Runnable and an
* inherited AccessControlContext.

View File

@ -27,8 +27,6 @@ package java.sql;
import java.time.Instant;
import java.time.LocalDate;
import jdk.internal.misc.SharedSecrets;
import jdk.internal.misc.JavaLangAccess;
/**
* <P>A thin wrapper around a millisecond value that allows
@ -46,8 +44,6 @@ import jdk.internal.misc.JavaLangAccess;
*/
public class Date extends java.util.Date {
private static final JavaLangAccess jla = SharedSecrets.getJavaLangAccess();
/**
* Constructs a <code>Date</code> object initialized with the given
* year, month, and day.
@ -168,7 +164,7 @@ public class Date extends java.util.Date {
buf[7] = '-';
Date.formatDecimalInt(day, buf, 8, 2);
return jla.newStringUnsafe(buf);
return new String(buf);
}
/**

View File

@ -27,8 +27,6 @@ package java.sql;
import java.time.Instant;
import java.time.LocalTime;
import jdk.internal.misc.SharedSecrets;
import jdk.internal.misc.JavaLangAccess;
/**
* <P>A thin wrapper around the <code>java.util.Date</code> class that allows the JDBC
@ -43,8 +41,6 @@ import jdk.internal.misc.JavaLangAccess;
*/
public class Time extends java.util.Date {
private static final JavaLangAccess jla = SharedSecrets.getJavaLangAccess();
/**
* Constructs a <code>Time</code> object initialized with the
* given values for the hour, minute, and second.
@ -134,7 +130,7 @@ public class Time extends java.util.Date {
buf[5] = ':';
Date.formatDecimalInt(second, buf, 6, 2);
return jla.newStringUnsafe(buf);
return new String(buf);
}
// Override all the date operations inherited from java.util.Date;

View File

@ -27,8 +27,6 @@ package java.sql;
import java.time.Instant;
import java.time.LocalDateTime;
import jdk.internal.misc.SharedSecrets;
import jdk.internal.misc.JavaLangAccess;
/**
* <P>A thin wrapper around {@code java.util.Date} that allows
@ -74,8 +72,6 @@ import jdk.internal.misc.JavaLangAccess;
*/
public class Timestamp extends java.util.Date {
private static final JavaLangAccess jla = SharedSecrets.getJavaLangAccess();
/**
* Constructs a {@code Timestamp} object initialized
* with the given values.
@ -313,7 +309,7 @@ public class Timestamp extends java.util.Date {
buf[yearSize + 15] = '.';
Date.formatDecimalInt(tmpNanos, buf, yearSize + 16, 9 - trailingZeros);
return jla.newStringUnsafe(buf);
return new String(buf);
}
/**

View File

@ -124,8 +124,6 @@ java/beans/Introspector/8132566/OverrideUserDefPropertyInfoTest.java 8132565 gen
java/lang/StringCoding/CheckEncodings.sh 7008363 generic-all
jdk/internal/misc/JavaLangAccess/NewUnsafeString.java 8176188 generic-all
java/lang/String/nativeEncoding/StringPlatformChars.java 8182569 windows-all,solaris-all
############################################################################

View File

@ -1,88 +0,0 @@
/*
* Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.util.Objects;
import java.util.Comparator;
import jdk.internal.misc.JavaLangAccess;
import jdk.internal.misc.SharedSecrets;
/*
* @test
* @bug 8013528
* @summary Test JavaLangAccess.newUnsafeString
* @modules java.base/jdk.internal.misc
* @compile -XDignore.symbol.file NewUnsafeString.java
* @run main NewUnsafeString
*/
public class NewUnsafeString {
static final JavaLangAccess jla = SharedSecrets.getJavaLangAccess();
public static void testNewUnsafeString() {
String benchmark = "exemplar";
String constructorCopy = new String(benchmark);
char[] jlaChars = benchmark.toCharArray();
String jlaCopy = jla.newStringUnsafe(jlaChars);
if (benchmark == constructorCopy) {
throw new Error("should be different instances");
}
if (!benchmark.equals(constructorCopy)) {
throw new Error("Copy not equal");
}
if (0 != Objects.compare(benchmark, constructorCopy, Comparator.naturalOrder())) {
throw new Error("Copy not equal");
}
if (benchmark == jlaCopy) {
throw new Error("should be different instances");
}
if (!benchmark.equals(jlaCopy)) {
throw new Error("Copy not equal");
}
if (0 != Objects.compare(benchmark, jlaCopy, Comparator.naturalOrder())) {
throw new Error("Copy not equal");
}
if (constructorCopy == jlaCopy) {
throw new Error("should be different instances");
}
if (!constructorCopy.equals(jlaCopy)) {
throw new Error("Copy not equal");
}
if (0 != Objects.compare(constructorCopy, jlaCopy, Comparator.naturalOrder())) {
throw new Error("Copy not equal");
}
// The following is extremely "evil". Never ever do this in non-test code.
jlaChars[0] = 'X';
if (!"Xxemplar".equals(jlaCopy)) {
throw new Error("jla.newStringUnsafe did not use provided string");
}
}
public static void main(String[] args) {
testNewUnsafeString();
}
}