# HG changeset patch # User shade # Date 1415832921 -10800 # Node ID 3c04b0fead02ed147f9556a7be56dbfbf88d5a0f # Parent d185cfc165dfb59c0553e26fa3ba39ac91357b68 8059677: Thread.getName() instantiates Strings Reviewed-by: chegar, dholmes, sla, rriggs diff -r d185cfc165df -r 3c04b0fead02 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; } /**