RFR: JDK-8318854: [macos14] Running any AWT app prints Secure coding warning [v2]
Harshitha Onkar
honkar at openjdk.org
Mon Nov 20 18:02:12 UTC 2023
On Fri, 10 Nov 2023 21:26:21 GMT, Sergey Bylokhov <serb at openjdk.org> wrote:
>> It can be null if the NSApplication was created by code outside of AWT. Specifically, in the case of an FX or SWT toolkit, but in theory a native application using JAWT could do this.
>>
>> In practice, since we haven't even seen a crash as a result of this, I doubt that this code is ever called if AWT isn't running the event loop and hasn't installed their delegate.
>
> To access any native code in AWT the app should initially init the LWCToolkit which sets that application delegate if it is not set already. Do we know how the FX can bypass that initialization?
@mrserb Shared delegate can be null if it is not installed when one of following conditions is met [ApplicationDelegate.m](https://github.com/openjdk/jdk/blob/5493f5f92d569d8e94d1f271480f11c48257e896/src/java.desktop/macosx/native/libawt_lwawt/awt/ApplicationDelegate.m#L118C4-L128C33) which is currently the case for Swing components embedded in FX window.
With https://github.com/openjdk/jfx/pull/1280 JavaFX NSApp is no longer of type NSApp, it is of type NSAppFX and considering the scenario - Swing components embedded in FX window, we hit the case where sharedDelegate is null at places where null checks have been added.
BOOL shouldInstall = NO;
BOOL overrideDelegate = (getenv("AWT_OVERRIDE_NSDELEGATE") != NULL);
if (NSApp != nil) {
if ([NSApp isMemberOfClass:[NSApplication class]] && overrideDelegate) shouldInstall = YES;
if ([NSApp isKindOfClass:[NSApplicationAWT class]]) shouldInstall = YES;
}
checked = YES;
if (!shouldInstall) return nil;
sApplicationDelegate = [[ApplicationDelegate alloc] init];
return sApplicationDelegate;
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/16569#discussion_r1399559545
More information about the client-libs-dev
mailing list