8029018: (bf) Check src/share/native/java/nio/Bits.c for JNI pending excepitons

Chris Hegarty chris.hegarty at oracle.com
Fri Jan 3 06:09:45 PST 2014


On 3 Jan 2014, at 13:51, Alan Bateman <Alan.Bateman at oracle.com> wrote:

> On 03/01/2014 13:36, Chris Hegarty wrote:
>> :
>> D’oh, you are assuming that on other VM’s there will be a pending exception if GetPrimitiveArrayCritical returns NULL. In which case, you could check for a pending exception and set one, if not already set, before returning. Or maybe this is just not worth it.
>> 
> Right, if GetPrimitiveArrayCritical were to return NULL (and I don't think it can in the HotSpot implementation) then it would do so with a pending exception. Checking for the exception is a good idea as it would eliminate any doubt around this. That would give us:
> 
> -#define GETCRITICAL(bytes, env, obj) { \
> +#define GETCRITICAL_OR_RETURN(bytes, env, obj) { \
>     bytes = (*env)->GetPrimitiveArrayCritical(env, obj, NULL); \
> -    if (bytes == NULL) \
> -        JNU_ThrowInternalError(env, "Unable to get array"); \
> +    if (bytes == NULL)  { \
> +        if ((*env)->ExceptionOccurred(env) == NULL) \
> +            JNU_ThrowInternalError(env, "Unable to get array"); \
> +        return; \
> +    } \
> }

Perfect.

-Chris.

> 
> -Alan.



More information about the nio-dev mailing list