RFR: 8329581: Java launcher no longer prints a stack trace [v10]

Thomas Stuefe stuefe at openjdk.org
Tue May 14 07:17:06 UTC 2024


On Mon, 13 May 2024 18:01:25 GMT, Sonia Zaldana Calles <szaldana at 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


More information about the core-libs-dev mailing list