United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-7175183 [macosx] Objective-C exception thrown when switching monitor configuration
JDK-7175183 : [macosx] Objective-C exception thrown when switching monitor configuration

Details
Type:
Bug
Submit Date:
2012-06-07
Status:
Resolved
Updated Date:
2012-12-18
Project Name:
JDK
Resolved Date:
2012-09-17
Component:
client-libs
OS:
os_x
Sub-Component:
java.awt
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
7u6
Fixed Versions:
7u40 (b08)

Related Reports
Backport:
Relates:

Sub Tasks

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
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();
                                     
2012-07-03
EVALUATION

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



Hardware and Software, Engineered to Work Together