From f2e3d67bf4acd7d421803a9af8680a376f27e5d7 Mon Sep 17 00:00:00 2001 From: chegar Date: Wed, 22 May 2013 13:50:53 +0100 Subject: [PATCH] 8010182: Thread safety of Thread get/setName() Reviewed-by: dholmes, alanb, mduigou --- src/share/classes/java/lang/Thread.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/share/classes/java/lang/Thread.java b/src/share/classes/java/lang/Thread.java index e418f1f9a..81bebc58b 100644 --- a/src/share/classes/java/lang/Thread.java +++ b/src/share/classes/java/lang/Thread.java @@ -145,10 +145,10 @@ class Thread implements Runnable { 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 @@ class Thread implements Runnable { * @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 @@ class Thread implements Runnable { * @see #setName(String) */ public final String getName() { - return String.valueOf(name); + return new String(name, true); } /** -- GitLab