On Tue, 14 May 2024 07:14:09 GMT, Thomas Stuefe <stu...@openjdk.org> wrote:
> 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?) This same issue comes up periodically and maybe the JNI spec needs improvement to make it clearer that returning NULL means there is a pending exception/error. JNI would be very broken if it were to return a jclass or ID and also raise an exception, or return NULL rather than a jclass or ID when it succeeds. As you say, it's not wrong to check both, just a bit strange as they can be just checks for NULL. At some point I think we need to do a round of cleanup here as these macros can mask other issues. It's not wrong to first check for a first exception, just a bit strange and not immediately clear what issues they may be masking. ------------- PR Comment: https://git.openjdk.org/jdk/pull/18786#issuecomment-2109495552