src/java.base/share/classes/java/lang/Thread.java
Print this page
@@ -143,11 +143,11 @@
private static native void registerNatives();
static {
registerNatives();
}
- private volatile char name[];
+ private volatile String name;
private int priority;
private Thread threadQ;
private long eetop;
/* Whether or not to single_step this thread. */
@@ -364,11 +364,11 @@
long stackSize, AccessControlContext acc) {
if (name == null) {
throw new NullPointerException("name cannot be null");
}
- this.name = name.toCharArray();
+ this.name = name;
Thread parent = currentThread();
SecurityManager security = System.getSecurityManager();
if (g == null) {
/* Determine if it's an applet or not */
@@ -1117,11 +1117,15 @@
* @see #getName
* @see #checkAccess()
*/
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);
}
}
@@ -1130,11 +1134,11 @@
*
* @return this thread's name.
* @see #setName(String)
*/
public final String getName() {
- return new String(name, true);
+ return name;
}
/**
* Returns the thread group to which this thread belongs.
* This method returns null if this thread has died