RFR (S): 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
Christian Thalinger
christian.thalinger at oracle.com
Thu Sep 26 20:13:24 UTC 2013
On Sep 26, 2013, at 11:50 AM, Christian Thalinger <christian.thalinger at oracle.com> wrote:
>
> 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:
>>> 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…
>
> 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.
Here are the two different versions:
http://cr.openjdk.java.net/~twisti/8019192/webrev.00/
http://cr.openjdk.java.net/~twisti/8019192/webrev.01/
>
>>
>> Regards, Peter
>>
>
More information about the core-libs-dev
mailing list