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

Alan Bateman Alan.Bateman at oracle.com
Fri Jan 3 05:51:41 PST 2014


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; \
+    } \
  }

-Alan.


More information about the nio-dev mailing list