6881442: (reflect) Race condition in Class.getName()
authormartin
Sat, 12 Sep 2009 15:30:13 -0700
changeset 3845 55b55f4c43d0
parent 3844 74c6b6e2db6c
child 3846 e4ada5ca68bf
6881442: (reflect) Race condition in Class.getName() Summary: only read "name" field racily once Reviewed-by: darcy
jdk/src/share/classes/java/lang/Class.java
--- a/jdk/src/share/classes/java/lang/Class.java	Fri Sep 11 16:36:22 2009 -0700
+++ b/jdk/src/share/classes/java/lang/Class.java	Sat Sep 12 15:30:13 2009 -0700
@@ -565,8 +565,9 @@
      *          represented by this object.
      */
     public String getName() {
+        String name = this.name;
         if (name == null)
-            name = getName0();
+            this.name = name = getName0();
         return name;
     }