提交 bbd59214 编写于 作者: S shade

8059677: Thread.getName() instantiates Strings

Reviewed-by: chegar, dholmes, sla, rriggs
上级 dde8b878
/* /*
* Copyright (c) 1994, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1994, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -145,7 +145,7 @@ class Thread implements Runnable { ...@@ -145,7 +145,7 @@ class Thread implements Runnable {
registerNatives(); registerNatives();
} }
private volatile char name[]; private volatile String name;
private int priority; private int priority;
private Thread threadQ; private Thread threadQ;
private long eetop; private long eetop;
...@@ -366,7 +366,7 @@ class Thread implements Runnable { ...@@ -366,7 +366,7 @@ class Thread implements Runnable {
throw new NullPointerException("name cannot be null"); throw new NullPointerException("name cannot be null");
} }
this.name = name.toCharArray(); this.name = name;
Thread parent = currentThread(); Thread parent = currentThread();
SecurityManager security = System.getSecurityManager(); SecurityManager security = System.getSecurityManager();
...@@ -1119,7 +1119,11 @@ class Thread implements Runnable { ...@@ -1119,7 +1119,11 @@ class Thread implements Runnable {
*/ */
public final synchronized void setName(String name) { public final synchronized void setName(String name) {
checkAccess(); checkAccess();
this.name = name.toCharArray(); if (name == null) {
throw new NullPointerException("name cannot be null");
}
this.name = name;
if (threadStatus != 0) { if (threadStatus != 0) {
setNativeName(name); setNativeName(name);
} }
...@@ -1132,7 +1136,7 @@ class Thread implements Runnable { ...@@ -1132,7 +1136,7 @@ class Thread implements Runnable {
* @see #setName(String) * @see #setName(String)
*/ */
public final String getName() { public final String getName() {
return new String(name, true); return name;
} }
/** /**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册