JDK-7132692 : [macosx] Class com.apple.eawt not functioning
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7,7u4
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: os_x
  • CPU: generic,x86
  • Submitted: 2012-01-24
  • Updated: 2012-03-23
  • Resolved: 2012-03-23
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7 JDK 8
7u4 b16Fixed 8Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
JDK 7 from http://jdk7.java.net/macportpreview/

*** I did Not get this string from command line output ***

ADDITIONAL OS VERSION INFORMATION :
Mac OS X 10.7.2

A DESCRIPTION OF THE PROBLEM :
This package works fine on Java 1.6 (by Apple) BUT NOT on Java 1.7 (current work in progress).  I tried to use the About, Preferences and Quit methods (these menu items are on the Apple menu on Mac), with the following results:

ABOUT - doesn't work at all - just gives default Java About

PREFERENCES - doen't work either from Apple menu or menu-shortcut (comma).

QUIT - works from Apple menu but NOT from menu-shortcut (Q).

In all cases where it doesn't work, I checked that the Handler is not being invoked. The code below is a simple app that displays a message when the handlers are invoked.  Works fine on Java 1.6 (from Apple).  Code has TWO class files.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Use the code above to interface with a simple Java app running on Mac OS X 10.7

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Accessing these items from the Apple menu, either with the mouse or with a standard menu-shortcut, should invoke the handler.
ACTUAL -
For about you get the default About box - this would be expected if you passed a null pointer to the handler, but I passed a valid reference

ERROR MESSAGES/STACK TRACES THAT OCCUR :
none - the submitted app logs whether or not the handlers are being invoked

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------

import java.awt.*;
import java.awt.event.*;

public class TestApp extends Frame implements LayoutManager, ActionListener {

	private AppleListener mAppleListener = null;
	private Label		mListenerLabel;
	private Label		mAboutLabel;
	private Label		mPreferencesLabel;
	private Label		mQuitLabel;
	private Button	mClearButton;

  public TestApp() {
    super("TestApp");
    setResizable(false);
    addNotify();
    setLayout(this);

    addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent event) {
			System.exit(0);
      }
    });

		try{
			try {
				mAppleListener = new AppleListener(this);
			} catch (Exception e) {}
		} catch (Error e) {}
		
		mListenerLabel = new Label("Listener " + (mAppleListener != null));
		add(mListenerLabel);
		mAboutLabel = new Label("---");
		add(mAboutLabel);
		mPreferencesLabel = new Label("---");
		add(mPreferencesLabel);
		mQuitLabel = new Label("---");
		add(mQuitLabel);
		mClearButton = new Button("Clear");
    mClearButton.addActionListener(this);
		add(mClearButton);
      
    setVisible(true);
    setSize(200, 300);
  }

  public final void addLayoutComponent(String n, Component c) {}
  public final void removeLayoutComponent(Component c) {}
  public final Dimension preferredLayoutSize(Container t)
		{return new Dimension(1, 1);}
  public final Dimension minimumLayoutSize(Container t)
		{return new Dimension(1, 1);}
  public final void layoutContainer(Container target)
  {
    mListenerLabel.setBounds(20, 50, 150, 20);
    mAboutLabel.setBounds(20, 100, 150, 20);
    mPreferencesLabel.setBounds(20, 150, 150, 20);
    mQuitLabel.setBounds(20, 200, 150, 20);
    mClearButton.setBounds(20, 250, 50, 30);
  }

  public void actionPerformed(ActionEvent e)
  {
    if (e.getSource() == mClearButton) {
			mAboutLabel.setText("---");
			mPreferencesLabel.setText("---");
			mQuitLabel.setText("---");
		}
	}

	public final void processAbout() {mAboutLabel.setText("processAbout");}
	public final void processPreferences(){mPreferencesLabel.setText("processPreferences");}
	public final void processQuit(){mQuitLabel.setText("processQuit");}

  public static void main(String args[]) {
    new TestApp();
  }
}

import com.apple.eawt.*;
public class AppleListener {
	
	private TestApp mTestApp;

  public AppleListener(TestApp controller) {
		mTestApp = controller;
		try{
			try {
				Application.getApplication().setAboutHandler(
					new AboutHandler() {
						public void handleAbout(AppEvent.AboutEvent e) {
							mTestApp.processAbout();
						}
					}
				);
				Application.getApplication().setPreferencesHandler(
					new PreferencesHandler() {
						public void handlePreferences(AppEvent.PreferencesEvent e) {
							mTestApp.processPreferences();
						}
					}
				);
				Application.getApplication().setQuitHandler(
					new QuitHandler() {
						public void handleQuitRequestWith(
							AppEvent.QuitEvent e, QuitResponse response) {
							mTestApp.processQuit();
							response.cancelQuit();
						}
					}
				);
			} catch (Exception e) {}
		} catch (Error e) {}
	}
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
None - I reported this as severe because it would severely impact Apps that are supposed to behave correctly on Mac OS using forthcoming Java 7.

Comments
EVALUATION NetBeans won't register an EAWT handler when running on Oracle JDK. I've filed a bug against NetBeans at http://netbeans.org/bugzilla/show_bug.cgi?id=208720
21-02-2012

EVALUATION 7130377 also gets resolved with the proposed solution.
13-02-2012

EVALUATION Setting the ApplicationDelegate *after* starting the event loop resolves the issue. In this case the QueuingApplicationDelegate always gets installed first, and then dispatches all queued notifications to the real ApplicationDelegate.
13-02-2012

EVALUATION If a splash screen is shown, then the eawt handlers work fine. W/o a splash screen the mainMenu is unavailable in ApplicationDelegate -init ([NSApp mainMenu] returns nil), and the handlers don't work. Looks like the issue is caused by different initialization paths when running with and w/o a splash screen.
10-02-2012