Race condition in Class.getName()
Joe Darcy
Joe.Darcy at Sun.COM
Fri Sep 11 23:48:48 UTC 2009
Martin Buchholz wrote:
> It is believed that the java memory model allows Class.getName()
> to return null.
> This is one of those methods with an intentional data race.
> Probably this has not been seen in practice because only
> a perverse or adversarial runtime would load the "name" field
> twice, out-of-order, as it seems to be allowed to.
>
> diff --git a/src/share/classes/java/lang/Class.java
> b/src/share/classes/java/lang/Class.java
> --- a/src/share/classes/java/lang/Class.java
> +++ b/src/share/classes/java/lang/Class.java
> @@ -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;
> }
>
> Martin
>
Hello.
The change looks fine to me. Do you want a bug filed, etc.?
-Joe
More information about the core-libs-dev
mailing list