# HG changeset patch # User anthony # Date 1340368359 -14400 # Node ID 01bc14f0979101ad0f0427883c9d57ae01252378 # Parent f6bf3300b4550d5c5c39279802967a38b1026f53 7170716: JVM crash when opening an AWT app from a registered file. Summary: Copy the queued blocks to prevent their deallocation Reviewed-by: anthony, swingler Contributed-by: Marco Dinacci diff -r f6bf3300b455 -r 01bc14f09791 jdk/src/macosx/native/sun/osxapp/QueuingApplicationDelegate.h --- a/jdk/src/macosx/native/sun/osxapp/QueuingApplicationDelegate.h Tue Jun 19 21:09:03 2012 +0400 +++ b/jdk/src/macosx/native/sun/osxapp/QueuingApplicationDelegate.h Fri Jun 22 16:32:39 2012 +0400 @@ -30,6 +30,8 @@ BOOL fHandlesDocumentTypes; BOOL fHandlesURLTypes; + id realDelegate; + NSMutableArray* queue; } @@ -40,5 +42,9 @@ - (void)processQueuedEventsWithTargetDelegate:(id )delegate; +@property(retain) id realDelegate; + +@property(retain) NSMutableArray* queue; + @end diff -r f6bf3300b455 -r 01bc14f09791 jdk/src/macosx/native/sun/osxapp/QueuingApplicationDelegate.m --- a/jdk/src/macosx/native/sun/osxapp/QueuingApplicationDelegate.m Tue Jun 19 21:09:03 2012 +0400 +++ b/jdk/src/macosx/native/sun/osxapp/QueuingApplicationDelegate.m Fri Jun 22 16:32:39 2012 +0400 @@ -27,8 +27,6 @@ #import "QueuingApplicationDelegate.h" -static id realDelegate = nil; - @interface NSBundle (EAWTOverrides) - (BOOL)_hasEAWTOverride:(NSString *)key; @end @@ -44,6 +42,9 @@ @implementation QueuingApplicationDelegate +@synthesize realDelegate; +@synthesize queue; + + (QueuingApplicationDelegate*) sharedDelegate { static QueuingApplicationDelegate * qad = nil; @@ -62,7 +63,7 @@ return self; } - self->queue = [[NSMutableArray arrayWithCapacity: 0] retain]; + self.queue = [NSMutableArray arrayWithCapacity: 0]; // If the java application has a bundle with an Info.plist file with // a CFBundleDocumentTypes entry, then it is set up to handle Open Doc @@ -100,8 +101,8 @@ Class clz = [QueuingApplicationDelegate class]; [ctr removeObserver:clz]; - [self->queue release]; - self->queue = nil; + self.queue = nil; + self.realDelegate = nil; [super dealloc]; } @@ -109,16 +110,16 @@ - (void)_handleOpenURLEvent:(NSAppleEventDescriptor *)openURLEvent withReplyEvent:(NSAppleEventDescriptor *)replyEvent { - [self->queue addObject:^(){ - [realDelegate _handleOpenURLEvent:openURLEvent withReplyEvent:replyEvent]; - }]; + [self.queue addObject:[^(){ + [self.realDelegate _handleOpenURLEvent:openURLEvent withReplyEvent:replyEvent]; + } copy]]; } - (void)application:(NSApplication *)theApplication openFiles:(NSArray *)fileNames { - [self->queue addObject:^(){ - [realDelegate application:theApplication openFiles:fileNames]; - }]; + [self.queue addObject:[^(){ + [self.realDelegate application:theApplication openFiles:fileNames]; + } copy]]; } - (NSApplicationPrintReply)application:(NSApplication *)application printFiles:(NSArray *)fileNames withSettings:(NSDictionary *)printSettings showPrintPanels:(BOOL)showPrintPanels @@ -127,9 +128,9 @@ return NSPrintingCancelled; } - [self->queue addObject:^(){ - [realDelegate application:application printFiles:fileNames withSettings:printSettings showPrintPanels:showPrintPanels]; - }]; + [self.queue addObject:[^(){ + [self.realDelegate application:application printFiles:fileNames withSettings:printSettings showPrintPanels:showPrintPanels]; + } copy]]; // well, a bit premature, but what else can we do?.. return NSPrintingSuccess; @@ -137,76 +138,76 @@ - (void)_willFinishLaunching { - QueuingApplicationDelegate * q = self; - [self->queue addObject:^(){ - [[realDelegate class] _willFinishLaunching]; - }]; + [self.queue addObject:[^(){ + [[self.realDelegate class] _willFinishLaunching]; + } copy]]; } - (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag { - [self->queue addObject:^(){ - [realDelegate applicationShouldHandleReopen:theApplication hasVisibleWindows:flag]; - }]; + [self.queue addObject:[^(){ + [self.realDelegate applicationShouldHandleReopen:theApplication hasVisibleWindows:flag]; + } copy]]; return YES; } - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)app { - [self->queue addObject:^(){ - [realDelegate applicationShouldTerminate:app]; - }]; + [self.queue addObject:[^(){ + [self.realDelegate applicationShouldTerminate:app]; + } copy]]; return NSTerminateLater; } - (void)_systemWillPowerOff { - [self->queue addObject:^(){ - [[realDelegate class] _systemWillPowerOff]; - }]; + [self.queue addObject:[^(){ + [[self.realDelegate class] _systemWillPowerOff]; + } copy]]; } - (void)_appDidActivate { - [self->queue addObject:^(){ - [[realDelegate class] _appDidActivate]; - }]; + [self.queue addObject:[^(){ + [[self.realDelegate class] _appDidActivate]; + } copy]]; } - (void)_appDidDeactivate { - [self->queue addObject:^(){ - [[realDelegate class] _appDidDeactivate]; - }]; + [self.queue addObject:[^(){ + [[self.realDelegate class] _appDidDeactivate]; + } copy]]; } - (void)_appDidHide { - [self->queue addObject:^(){ - [[realDelegate class] _appDidHide]; - }]; + [self.queue addObject:[^(){ + [[self.realDelegate class] _appDidHide]; + } copy]]; } - (void)_appDidUnhide { - [self->queue addObject:^(){ - [[realDelegate class] _appDidUnhide]; - }]; + [self.queue addObject:[^(){ + [[self.realDelegate class] _appDidUnhide]; + } copy]]; } - (void)processQueuedEventsWithTargetDelegate:(id )delegate { + self.realDelegate = delegate; + NSUInteger i; - NSUInteger count = [self->queue count]; - - realDelegate = delegate; + NSUInteger count = [self.queue count]; for (i = 0; i < count; i++) { - void (^event)() = (void (^)())[self->queue objectAtIndex: i]; + void (^event)() = (void (^)())[self.queue objectAtIndex: i]; event(); + [event release]; } - [self->queue removeAllObjects]; + [self.queue removeAllObjects]; } @end