On Mon, 13 May 2024 18:01:25 GMT, Sonia Zaldana Calles <szald...@openjdk.org> 
wrote:

> > This mostly looks good. I'm just puzzled CHECK_EXCEPTION_NULL_FAIL. The JNI 
> > functions GetStaticMethodID, GetMethodID and NewObject return NULL with a 
> > pending exception when they fail. So I would expect 
> > CHECK_EXCEPTION_NULL_FAIL to just check if obj is NULL rather check for an 
> > exception first. It's not wrong to check for an exception, just curious 
> > when looking at this macro.
> 
> Hi @AlanBateman, thanks for taking a look. That's a good point - would it be 
> worthwhile to delete the exception check in this case?

Well, its not wrong, and arguably more defensive.

Doc for GetStaticMethodID states:


RETURNS:
Returns a method ID, or NULL if the operation fails.

THROWS:
NoSuchMethodError: if the specified static method cannot be found.
ExceptionInInitializerError: if the class initializer fails due to an exception.
OutOfMemoryError: if the system runs out of memory.


but it does not state explicitly that an exception is thrown on every error, or 
whether there are cases where the API can return NULL but not throw an 
exception, or vice versa.

So, I'd check for both. Or, if we think that both should not happen or happen 
together, assert that. (we can use the standard C assert in the JDK libraries, 
no?)

-------------

PR Comment: https://git.openjdk.org/jdk/pull/18786#issuecomment-2109450146

Reply via email to