RFR (S): 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()

Peter Levart peter.levart at gmail.com
Thu Sep 26 01:22:44 PDT 2013


On 09/26/2013 01:27 AM, Christian Thalinger wrote:
> http://cr.openjdk.java.net/~twisti/8019192/webrev/
>
> 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
> Reviewed-by:
>
> This is a race in MemberName's name and type getters.
>
> MemberName's type field is of type Object so it can hold different objects when it gets filled in from the VM.  These types include String and Object[].  On the first invocation the current type if it's not MethodType gets converted to a MethodType.
>
> There is a tiny window where some instanceof check have already been done on one thread and then another thread stores a MethodType.  The following checkcast then fails.
>
> The fix is to make name and type volatile and do the conversion in a synchronized block.  This is okay because it's only done once.
>
> src/share/classes/java/lang/invoke/MemberName.java
>

Hi Christian,

Wouldn't it be cleaner that instead of just casting and catching 
ClassCastException, the volatile field 'type' was 1st copied to a local 
variable and then an instanceof check + casting and returning performed 
on the local variable. This would avoid throwing ClassCastException even 
if it is performed only once per MemberName...

Regards, Peter



More information about the hotspot-compiler-dev mailing list