RFR: 8259343: [macOS] Update JNI error handling in Cocoa code. [v3]
Sergey Bylokhov
serb at openjdk.java.net
Tue Jan 12 02:41:00 UTC 2021
On Mon, 11 Jan 2021 17:09:14 GMT, Phil Race <prr at openjdk.org> wrote:
>> src/java.desktop/macosx/native/libosxapp/JNIUtilities.h line 41:
>>
>>> 39: NSLog(@"%@",[NSThread callStackSymbols]); \
>>> 40: if ([NSThread isMainThread] == NO) { \
>>> 41: if ((*env)->ExceptionOccurred(env) == NULL) { \
>>
>> Not sure that the check for ExceptionOccurred is needed, in all other places where we check the ref to methods/field we only check the return value, and if it is null then return immediately assuming that an exception is rased already, for example :
>> https://github.com/openjdk/jdk/blob/b72de3c5fc99f365e9fb25114ddd28eceddfa6e8/src/java.desktop/windows/native/libawt/windows/awt_Button.cpp#L357
>>
>> Note that the exception in the static initializer is fatal for the application.
>
>> Not sure that the check for ExceptionOccurred is needed,
> It may not be needed in practice but if the code path is never taken no harm ...
>
> in all other places where we check the ref to methods/field we only check the return value, and if it is null then return immediately assuming that an exception is rased already, for example :
>>
>> https://github.com/openjdk/jdk/blob/b72de3c5fc99f365e9fb25114ddd28eceddfa6e8/src/java.desktop/windows/native/libawt/windows/awt_Button.cpp#L357
>>
>> Note that the exception in the static initializer is fatal for the application.
>
> Nothing new here.
The new thing here is that you check the result of the ExceptionOccurred if NULL is returned from the GetMethodID/etc, we usually never do it. If such checks are necessary then I'll create a separate bug to update other similar use cases.
-------------
PR: https://git.openjdk.java.net/jdk/pull/1967
More information about the build-dev
mailing list