changeset 11038:0bddfc90d139

8059677: Thread.getName() instantiates Strings Reviewed-by: chegar, dholmes, sla, rriggs
author shade
date Thu, 13 Nov 2014 01:55:21 +0300
parents a579414719c5
children 0fc5f059eeed
files src/java.base/share/classes/java/lang/Thread.java
diffstat 1 files changed, 8 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/lang/Thread.java	Tue Nov 11 21:46:02 2014 -0800
+++ b/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;
     }
 
     /**