RFR (S): 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
christian.thalinger at oracle.com
Thu Sep 26 11:50:05 PDT 2013
On Sep 26, 2013, at 1:22 AM, Peter Levart <peter.levart at gmail.com> wrote:
> On 09/26/2013 01:27 AM, Christian Thalinger wrote:
>> 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
>> 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.
> 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…
Not sure it would be cleaner; depends on the definition of "cleaner". I had similar code as you describe before but I changed it to catch the exception. If people have a strong opinion here I can change it back.
> Regards, Peter
More information about the hotspot-compiler-dev