JDK-7175183 : [macosx] Objective-C exception thrown when switching monitor configuration
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7u6
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: os_x
  • CPU: x86
  • Submitted: 2012-06-07
  • Updated: 2016-02-02
  • Resolved: 2012-09-17
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
7u40 b08Fixed 8Fixed
Related Reports
Relates :  
Description
When switching monitor configurations I get a NullPointerException and then an Objective-C exception.

Note: I believe these are the steps to reproduce, as I arrived to work to find this exception.

This was using a local top-of-branch build from jdk7u-dev. To reproduce you will need a MacBook Pro and an external monitor. Start with just the MacBook; no monitor connected.

1. Install the Mac OS X JRE from http://jdk7.java.net/macportpreview/
2. Run

/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/jcontrol

3. Leave the control panel open, and close the laptop. Now, connect a monitor and keyboard so you can see the desktop on the external monitor.
4. You should see a pair of exceptions:

2012-06-07 10:26:30.430 java[1590:707] java.lang.NullPointerException
	at sun.awt.image.VolatileSurfaceManager.displayChanged(VolatileSurfaceManager.java:340)
	at sun.awt.SunDisplayChanger.notifyListeners(SunDisplayChanger.java:132)
	at sun.java2d.SunGraphicsEnvironment.displayChanged(SunGraphicsEnvironment.java:281)
	at sun.awt.CGraphicsEnvironment._displayReconfiguration(CGraphicsEnvironment.java:119)
2012-06-07 10:26:31.650 java[1590:707] (
	0   CoreFoundation                      0x00007fff8a744f56 __exceptionPreprocess + 198
	1   libobjc.A.dylib                     0x00007fff8d4aad5e objc_exception_throw + 43
	2   CoreFoundation                      0x00007fff8a7cf1b9 -[NSException raise] + 9
	3   JavaNativeFoundation                0x0000000116787541 JNFCallVoidMethod + 209
	4   liblwawt.dylib                      0x0000000117000bec __displaycb_handle_block_invoke_1 + 58
	5   JavaNativeFoundation                0x000000011678918a JNFPerformEnvBlock + 86
	6   liblwawt.dylib                      0x0000000117000bac displaycb_handle + 78
	7   CoreGraphics                        0x00007fff8eae105f displayConfigFinalizedProc + 377
	8   CoreGraphics                        0x00007fff8e5bc867 CGSPostLocalNotification + 237
	9   CoreGraphics                        0x00007fff8e67ed3d notifyDatagramHandler + 260
	10  CoreGraphics                        0x00007fff8e67eabf CGSDispatchDatagramsFromStream + 268
	11  CoreGraphics                        0x00007fff8e67e6a4 snarfEvents + 437
	12  CoreGraphics                        0x00007fff8e67e3a7 CGSGetNextEventRecordInternal + 110
	13  CoreGraphics                        0x00007fff8e6cca19 CGEventCreateNextEvent + 29
	14  HIToolbox                           0x00007fff8de55f6a _ZL38PullEventsFromWindowServerOnConnectionjh + 69
	15  CoreFoundation                      0x00007fff8a6a3c52 __CFMachPortPerform + 386
	16  CoreFoundation                      0x00007fff8a6a3abc __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 44
	17  CoreFoundation                      0x00007fff8a6a37eb __CFRunLoopDoSource1 + 155
	18  CoreFoundation                      0x00007fff8a6d9f27 __CFRunLoopRun + 1895
	19  CoreFoundation                      0x00007fff8a6d9486 CFRunLoopRunSpecific + 230
	20  HIToolbox                           0x00007fff8de404d3 RunCurrentEventLoopInMode + 277
	21  HIToolbox                           0x00007fff8de47781 ReceiveNextEventCommon + 355
	22  HIToolbox                           0x00007fff8de4760e BlockUntilNextEventMatchingListInMode + 62
	23  AppKit                              0x00007fff8b1a5e31 _DPSNextEvent + 659
	24  AppKit                              0x00007fff8b1a5735 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 135
	25  libosxapp.dylib                     0x000000011709e82c -[NSApplicationAWT nextEventMatchingMask:untilDate:inMode:dequeue:] + 124
	26  AppKit                              0x00007fff8b1a2071 -[NSApplication run] + 470
	27  libosxapp.dylib                     0x000000011709e74b +[NSApplicationAWT runAWTLoopWithApp:] + 156
	28  liblwawt.dylib                      0x0000000116ffafea -[AWTStarter starter:] + 1587
	29  CoreFoundation                      0x00007fff8a73470d -[NSObject performSelector:withObject:] + 61
	30  Foundation                          0x00007fff870a6d70 __NSThreadPerformPerform + 214
	31  CoreFoundation                      0x00007fff8a6b34f1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
	32  CoreFoundation                      0x00007fff8a6b2d5d __CFRunLoopDoSources0 + 253
	33  CoreFoundation                      0x00007fff8a6d9b49 __CFRunLoopRun + 905
	34  CoreFoundation                      0x00007fff8a6d9486 CFRunLoopRunSpecific + 230
	35  java                                0x000000010c6dc4bc CreateExecutionEnvironment + 871
	36  java                                0x000000010c6d6cac JLI_Launch + 1952
	37  java                                0x000000010c6dc819 main + 101
	38  java                                0x000000010c6d6504 start + 52
)

The Control Panel does not crash and doesn't seem to be affected by the error, but these kind of exceptions are not good in final code.
The 7u6 RT wants to take the fix that is listed in the bug and then recommends that a new bug be opened to fix the real proble.

Comments
Verified
06-09-2013

EVALUATION Need to backport change from jdk8 that eliminates this NPE.
06-09-2012

SUGGESTED FIX I have been using this patch for a while now, and it has made the 7 AWT more stable, particularly with NetBeans. It's probably worth understanding why the objects in question are null, but for now I think it's a good fix. ============================= diff --git a/src/macosx/native/sun/awt/CWrapper.m b/src/macosx/native/sun/awt/CWrapper.m --- a/src/macosx/native/sun/awt/CWrapper.m +++ b/src/macosx/native/sun/awt/CWrapper.m @@ -46,9 +46,11 @@ JNF_COCOA_ENTER(env); id obj = (id)jlong_to_ptr(objectPtr); + if (obj != nil) { [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ CFRelease(obj); }]; + } JNF_COCOA_EXIT(env); } diff --git a/src/share/classes/sun/awt/image/VolatileSurfaceManager.java b/src/share/classes/sun/awt/image/VolatileSurfaceManager.java --- a/src/share/classes/sun/awt/image/VolatileSurfaceManager.java +++ b/src/share/classes/sun/awt/image/VolatileSurfaceManager.java @@ -335,10 +335,13 @@ sdBackup = null; sdCurrent = getBackupSurface(); // Now, invalidate the old hardware-based SurfaceData + // Note that getBackupSurface may set sdAccel to null!! + if (sdAccel != null) { SurfaceData oldData = sdAccel; sdAccel = null; oldData.invalidate(); } + } // Update graphicsConfig for the vImg in case it changed due to // this display change event vImg.updateGraphicsConfig();
03-07-2012