8059677: Thread.getName() instantiates Strings
Reviewed-by: chegar, dholmes, sla, rriggs
--- 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;
}
/**