8176188: jdk/internal/misc/JavaLangAccess/NewUnsafeString.java failing since 9-b93
authorredestad
Tue, 05 Dec 2017 14:25:16 +0100
changeset 48065 c4f2b6749c86
parent 48064 390794d000e6
child 48066 df95bd1fd4b1
8176188: jdk/internal/misc/JavaLangAccess/NewUnsafeString.java failing since 9-b93 Reviewed-by: psandoz, sherman
src/java.base/share/classes/java/lang/String.java
src/java.base/share/classes/java/lang/System.java
src/java.base/share/classes/java/util/StringJoiner.java
src/java.base/share/classes/jdk/internal/misc/JavaLangAccess.java
src/java.sql/share/classes/java/sql/Date.java
src/java.sql/share/classes/java/sql/Time.java
src/java.sql/share/classes/java/sql/Timestamp.java
test/jdk/ProblemList.txt
test/jdk/jdk/internal/misc/JavaLangAccess/NewUnsafeString.java
--- a/src/java.base/share/classes/java/lang/String.java	Tue Dec 05 14:10:11 2017 +0100
+++ b/src/java.base/share/classes/java/lang/String.java	Tue Dec 05 14:25:16 2017 +0100
@@ -645,19 +645,6 @@
         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
--- a/src/java.base/share/classes/java/lang/System.java	Tue Dec 05 14:10:11 2017 +0100
+++ b/src/java.base/share/classes/java/lang/System.java	Tue Dec 05 14:25:16 2017 +0100
@@ -2109,9 +2109,6 @@
             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);
             }
--- a/src/java.base/share/classes/java/util/StringJoiner.java	Tue Dec 05 14:10:11 2017 +0100
+++ b/src/java.base/share/classes/java/util/StringJoiner.java	Tue Dec 05 14:25:16 2017 +0100
@@ -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 @@
      */
     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 @@
             }
         }
         k += getChars(suffix, chars, k);
-        return jla.newStringUnsafe(chars);
+        return new String(chars);
     }
 
     /**
@@ -252,7 +247,7 @@
                 elts[i] = null;
             } while (++i < size);
             size = 1;
-            elts[0] = jla.newStringUnsafe(chars);
+            elts[0] = new String(chars);
         }
     }
 
--- a/src/java.base/share/classes/jdk/internal/misc/JavaLangAccess.java	Tue Dec 05 14:10:11 2017 +0100
+++ b/src/java.base/share/classes/jdk/internal/misc/JavaLangAccess.java	Tue Dec 05 14:25:16 2017 +0100
@@ -124,16 +124,6 @@
     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.
      */
--- a/src/java.sql/share/classes/java/sql/Date.java	Tue Dec 05 14:10:11 2017 +0100
+++ b/src/java.sql/share/classes/java/sql/Date.java	Tue Dec 05 14:25:16 2017 +0100
@@ -27,8 +27,6 @@
 
 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 @@
  */
 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 @@
         buf[7] = '-';
         Date.formatDecimalInt(day, buf, 8, 2);
 
-        return jla.newStringUnsafe(buf);
+        return new String(buf);
     }
 
     /**
--- a/src/java.sql/share/classes/java/sql/Time.java	Tue Dec 05 14:10:11 2017 +0100
+++ b/src/java.sql/share/classes/java/sql/Time.java	Tue Dec 05 14:25:16 2017 +0100
@@ -27,8 +27,6 @@
 
 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 @@
  */
 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 @@
         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;
--- a/src/java.sql/share/classes/java/sql/Timestamp.java	Tue Dec 05 14:10:11 2017 +0100
+++ b/src/java.sql/share/classes/java/sql/Timestamp.java	Tue Dec 05 14:25:16 2017 +0100
@@ -27,8 +27,6 @@
 
 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 @@
  */
 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 @@
         buf[yearSize + 15] = '.';
         Date.formatDecimalInt(tmpNanos, buf, yearSize + 16, 9 - trailingZeros);
 
-        return jla.newStringUnsafe(buf);
+        return new String(buf);
     }
 
     /**
--- a/test/jdk/ProblemList.txt	Tue Dec 05 14:10:11 2017 +0100
+++ b/test/jdk/ProblemList.txt	Tue Dec 05 14:25:16 2017 +0100
@@ -124,8 +124,6 @@
 
 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
 
 ############################################################################
--- a/test/jdk/jdk/internal/misc/JavaLangAccess/NewUnsafeString.java	Tue Dec 05 14:10:11 2017 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -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();
-    }
-}