diff --git a/src/java.base/share/classes/java/lang/String.java b/src/java.base/share/classes/java/lang/String.java index db55267ee83..e3da498617c 100644 --- a/src/java.base/share/classes/java/lang/String.java +++ b/src/java.base/share/classes/java/lang/String.java @@ -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 Unicode diff --git a/src/java.base/share/classes/java/lang/System.java b/src/java.base/share/classes/java/lang/System.java index 0232642b42c..6271f87a6f0 100644 --- a/src/java.base/share/classes/java/lang/System.java +++ b/src/java.base/share/classes/java/lang/System.java @@ -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); } diff --git a/src/java.base/share/classes/java/util/StringJoiner.java b/src/java.base/share/classes/java/util/StringJoiner.java index 3dca2df4d46..c72d5a213bd 100644 --- a/src/java.base/share/classes/java/util/StringJoiner.java +++ b/src/java.base/share/classes/java/util/StringJoiner.java @@ -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); } } diff --git a/src/java.base/share/classes/jdk/internal/misc/JavaLangAccess.java b/src/java.base/share/classes/jdk/internal/misc/JavaLangAccess.java index 90ec8f40761..7561b2109ad 100644 --- a/src/java.base/share/classes/jdk/internal/misc/JavaLangAccess.java +++ b/src/java.base/share/classes/jdk/internal/misc/JavaLangAccess.java @@ -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. diff --git a/src/java.sql/share/classes/java/sql/Date.java b/src/java.sql/share/classes/java/sql/Date.java index a6d8d8f4016..f8da3e7f94b 100644 --- a/src/java.sql/share/classes/java/sql/Date.java +++ b/src/java.sql/share/classes/java/sql/Date.java @@ -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; /** *

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 Date 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); } /** diff --git a/src/java.sql/share/classes/java/sql/Time.java b/src/java.sql/share/classes/java/sql/Time.java index 3d1f237933c..281d031c7c1 100644 --- a/src/java.sql/share/classes/java/sql/Time.java +++ b/src/java.sql/share/classes/java/sql/Time.java @@ -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; /** *

A thin wrapper around the java.util.Date 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 Time 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; diff --git a/src/java.sql/share/classes/java/sql/Timestamp.java b/src/java.sql/share/classes/java/sql/Timestamp.java index 968d6e76b9f..4b4c334dd45 100644 --- a/src/java.sql/share/classes/java/sql/Timestamp.java +++ b/src/java.sql/share/classes/java/sql/Timestamp.java @@ -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; /** *

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); } /** diff --git a/test/jdk/ProblemList.txt b/test/jdk/ProblemList.txt index 07fb5b5d51f..7071399994e 100644 --- a/test/jdk/ProblemList.txt +++ b/test/jdk/ProblemList.txt @@ -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 ############################################################################ diff --git a/test/jdk/jdk/internal/misc/JavaLangAccess/NewUnsafeString.java b/test/jdk/jdk/internal/misc/JavaLangAccess/NewUnsafeString.java deleted file mode 100644 index 302fb185809..00000000000 --- a/test/jdk/jdk/internal/misc/JavaLangAccess/NewUnsafeString.java +++ /dev/null @@ -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(); - } -}