United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-8011686 [macosx] AWT accidentally disables the NSApplicationDelegate of SWT, causing loss of OS X integration functionality
JDK-8011686 : [macosx] AWT accidentally disables the NSApplicationDelegate of SWT, causing loss of OS X integration functionality

Details
Type:
Bug
Submit Date:
2013-04-08
Status:
Resolved
Updated Date:
2013-07-02
Project Name:
JDK
Resolved Date:
2013-04-18
Component:
client-libs
OS:
os_x
Sub-Component:
java.awt
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
7u17,8
Fixed Versions:

Related Reports
Backport:
Backport:
Backport:

Sub Tasks

Description
If the AWT native code (in awt.m) is loaded after SWT (or any other toolkit) has initialized its custom NSApplication subclass, AWT does not create its own NSApplicationDelegate (which might be ok). Instead AWT (by accident?) removes the currently installed app delegate. Effectively it does [NSApp setDelegate: nil]. This causes SWT apps to lose OS X integration functionality. Many bugs likely caused by this has been filed on both SWT and the JDK. I will add them to this bug as I find them. Note that this bug does not happen with Apple's JDK 6.

There is a trivial fix to this (don't call setDelegate: with nil), that certainly will improve things.

However, since at least SWT tries to obtain the AWT app delegate, and delegates certain methods to it (as well as handling them itself), maybe the AWT app delegate should be created, but just not installed using setDelegate:. Comments in [ApplicationDelegate sharedDelegate] suggests that this was the intent. But in this case, the logic in [ApplicationDelegate init] should likely be revised so that it acts more like if usingDefaultNib was NO by default, but perhaps not completely. This might be tricky and likely more suitable for a general overhaul like suggested in JDK-8006326.

This bug affects Java Mission Control which is Eclipse/SWT based (but has plug-ins using AWT), and is scheduled for inclusion in later JDK 7 updates as well as in JDK 8.
                                    

Comments
A symptom of this bug (since the SWT app delegate does not receive applicationShouldTerminate:)
JI-9000562 (originally https://bugs.eclipse.org/bugs/show_bug.cgi?id=399091 )

                                     
2013-04-08
The offending code is in src/macosx/native/sun/awt/awt.m, in the implementation of [AWTStarter start:], near the end. The surrounding code differs between JDK 7 and JDK 8 master, but the culprit is always:

   OSXAPP_SetApplicationDelegate([ApplicationDelegate sharedDelegate]);

This should be replaced with something like:

   id <NSApplicationDelegate> delegate = [ApplicationDelegate sharedDelegate];
   // Only set the delegate if non-nil, to prevent removing an existing delegate from another toolkit, like SWT.
   if (delegate) {
      OSXAPP_SetApplicationDelegate(delegate);
   }
                                     
2013-04-08
URL:   http://hg.openjdk.java.net/jdk8/awt/jdk/rev/c70346f4c0a9
User:  serb
Date:  2013-04-18 14:12:31 +0000

                                     
2013-04-18
URL:   http://hg.openjdk.java.net/jdk8/jdk8/jdk/rev/c70346f4c0a9
User:  lana
Date:  2013-05-07 18:40:01 +0000

                                     
2013-05-07
This needs to be fixed in 7u40, otherwise this will happen: 
https://bug.oraclecorp.com/pls/bug/webbug_print.show?c_rptno=16208145
                                     
2013-06-13
SQE: OK to 7u40.

Interesting that 7u40 before the fix works properly started on the first thread  in an ssh session. It tries and fails to initialize headless mode and perhaps does not overwrite this delegate.
I don't think an application would work reliably though.
                                     
2013-06-19
In 7u40 we have a specific check for headless mode when setting the delegate. 
We do not have one in JDK8 because currently we do not load libawt_lwawt.dylib in headless mode in 8. These differences are tracked by another issues: (JDK-2224144 and JDK-2226108).
                                     
2013-06-19
Since we have the SQE - OK for 7u40 - I will approve this request.
                                     
2013-06-20



Hardware and Software, Engineered to Work Together