8059677: Thread.getName() instantiates Strings
authorshade
Thu, 13 Nov 2014 01:55:21 +0300
changeset 27786 3c04b0fead02
parent 27739 d185cfc165df
child 27787 c77e5961a208
8059677: Thread.getName() instantiates Strings Reviewed-by: chegar, dholmes, sla, rriggs
jdk/src/java.base/share/classes/java/lang/Thread.java
--- a/jdk/src/java.base/share/classes/java/lang/Thread.java	Tue Nov 11 21:46:02 2014 -0800
+++ b/jdk/src/java.base/share/classes/java/lang/Thread.java	Thu Nov 13 01:55:21 2014 +0300
@@ -145,7 +145,7 @@
         registerNatives();
     }
 
-    private volatile char  name[];
+    private volatile String name;
     private int            priority;
     private Thread         threadQ;
     private long           eetop;
@@ -366,7 +366,7 @@
             throw new NullPointerException("name cannot be null");
         }
 
-        this.name = name.toCharArray();
+        this.name = name;
 
         Thread parent = currentThread();
         SecurityManager security = System.getSecurityManager();
@@ -1119,7 +1119,11 @@
      */
     public final synchronized void setName(String name) {
         checkAccess();
-        this.name = name.toCharArray();
+        if (name == null) {
+            throw new NullPointerException("name cannot be null");
+        }
+
+        this.name = name;
         if (threadStatus != 0) {
             setNativeName(name);
         }
@@ -1132,7 +1136,7 @@
      * @see     #setName(String)
      */
     public final String getName() {
-        return new String(name, true);
+        return name;
     }
 
     /**