changeset 7209:48e8a6e0c805

8010182: Thread safety of Thread get/setName() Reviewed-by: dholmes, alanb, mduigou
author chegar
date Wed, 22 May 2013 13:50:53 +0100
parents 1fba35ef4360
children 4b555b53dc57 bcfab7056195
files src/share/classes/java/lang/Thread.java
diffstat 1 files changed, 6 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/lang/Thread.java	Tue May 21 01:50:13 2013 -0700
+++ b/src/share/classes/java/lang/Thread.java	Wed May 22 13:50:53 2013 +0100
@@ -145,10 +145,10 @@
         registerNatives();
     }
 
-    private char        name[];
-    private int         priority;
-    private Thread      threadQ;
-    private long        eetop;
+    private volatile char  name[];
+    private int            priority;
+    private Thread         threadQ;
+    private long           eetop;
 
     /* Whether or not to single_step this thread. */
     private boolean     single_step;
@@ -1135,7 +1135,7 @@
      * @see        #getName
      * @see        #checkAccess()
      */
-    public final void setName(String name) {
+    public final synchronized void setName(String name) {
         checkAccess();
         this.name = name.toCharArray();
         if (threadStatus != 0) {
@@ -1150,7 +1150,7 @@
      * @see     #setName(String)
      */
     public final String getName() {
-        return String.valueOf(name);
+        return new String(name, true);
     }
 
     /**