| Summary: | [Cocoa] OS X: NPE in Control.internal_new_GC | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| Product: | [Eclipse Project] Platform | Reporter: | Thomas Singer <eclipse> | ||||||
| Component: | SWT | Assignee: | Lakshmi P Shanmugam <lshanmug> | ||||||
| Status: | RESOLVED FIXED | QA Contact: | |||||||
| Severity: | critical | ||||||||
| Priority: | P3 | CC: | abhishek.kishore, adripol1994, alexander.stahlberg, andreas.buchen, arunkumar.thondapu, boingolover, dave.nice, error-reports-inbox, eyck, fura, gattacus, hubert+eclipseorg, kate.labeeva, lshanmug, mail, marcel.bruch, nick, niraj.modi, picard, pujos.michael, superstippi, tom.schindl | ||||||
| Version: | 4.4 | ||||||||
| Target Milestone: | 4.5.2 | ||||||||
| Hardware: | PC | ||||||||
| OS: | Mac OS X | ||||||||
| Whiteboard: | |||||||||
| Bug Depends on: | |||||||||
| Bug Blocks: | 482454 | ||||||||
| Attachments: |
|
||||||||
|
Description
Thomas Singer
Another stacktrace after restarting the application is: java.lang.NullPointerException at org.eclipse.swt.widgets.Control.internal_new_GC(Control.java:2134) at org.eclipse.swt.graphics.GC.<init>(GC.java:171) at org.eclipse.swt.graphics.GC.<init>(GC.java:134) at org.eclipse.swt.custom.CLabel.getTotalSize(CLabel.java:260) at org.eclipse.swt.custom.CLabel.onPaint(CLabel.java:400) at org.eclipse.swt.custom.CLabel$1.paintControl(CLabel.java:121) at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:230) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84) at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4166) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1466) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1489) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1474) at org.eclipse.swt.widgets.Control.drawWidget(Control.java:1244) at org.eclipse.swt.widgets.Canvas.drawWidget(Canvas.java:166) at org.eclipse.swt.widgets.Widget.drawRect(Widget.java:749) at org.eclipse.swt.widgets.Canvas.drawRect(Canvas.java:161) at org.eclipse.swt.widgets.Display.windowProc(Display.java:5534) at org.eclipse.swt.internal.cocoa.OS.objc_msgSend_bool(Native Method) at org.eclipse.swt.internal.cocoa.NSRunLoop.runMode(NSRunLoop.java:42) at org.eclipse.swt.widgets.Display.sleep(Display.java:4610) *** Bug 439238 has been marked as a duplicate of this bug. *** This bug has been present in the OS X version of SWT for a while. I've never seen it myself, but only in crash-logs from users. I've surrounded code which creates a new GC for a given Widget (for example to compute the size) with try-catch-blocks if it is non-critical code. From the logs we receive from users, the error seems to be non-permanent. It also appears to affect only certain places in the code, i.e. I have more places where a GC is created, but only some throw the error. In a certain version of our software, a place started to throw NPEs which previously never triggered it, but there were no changes in that part of the code for a number of versions. I have only one faint suspicion which is that the GC is created completely outside of any drawing or layout related event. I.e. a string changes in the interface, the app doesn't call layout() on any Composite directly, but instead wants to figure out if a layout is necessary by first computing whether the size actually changed in a certain way. Also has been for the latest OS X version XI. Alot of users report this problem for SmartGit 6.5 on OS X 10.11 preview - much more often than for any previous OS X version. Here are a couple of more similar stacktraces: java.lang.NullPointerException at org.eclipse.swt.widgets.Control.internal_new_GC(Control.java:2118) at org.eclipse.swt.graphics.GC.cocoa_new(GC.java:207) at org.eclipse.swt.widgets.Table.sendMeasureItem(Table.java:3088) at org.eclipse.swt.widgets.Table.cellSize(Table.java:235) at org.eclipse.swt.widgets.Display.windowProc(Display.java:5517) at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper_stret(Native Method) at org.eclipse.swt.widgets.Widget.expansionFrameWithFrame_inView(Widget.java:798) at org.eclipse.swt.widgets.Table.expansionFrameWithFrame_inView(Table.java:1182) at org.eclipse.swt.widgets.Display.windowProc(Display.java:5896) at org.eclipse.swt.internal.cocoa.OS.objc_msgSend_bool(Native Method) at org.eclipse.swt.internal.cocoa.NSRunLoop.runMode(NSRunLoop.java:42) at org.eclipse.swt.widgets.Display.sleep(Display.java:4680) java.lang.NullPointerException at org.eclipse.swt.widgets.Control.internal_new_GC(Control.java:2118) at org.eclipse.swt.graphics.GC.cocoa_new(GC.java:207) at org.eclipse.swt.widgets.Tree.sendMeasureItem(Tree.java:2593) at org.eclipse.swt.widgets.Tree.cellSize(Tree.java:288) at org.eclipse.swt.widgets.Display.windowProc(Display.java:5517) at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper_stret(Native Method) at org.eclipse.swt.widgets.Widget.expansionFrameWithFrame_inView(Widget.java:798) at org.eclipse.swt.widgets.Tree.expansionFrameWithFrame_inView(Tree.java:1271) at org.eclipse.swt.widgets.Display.windowProc(Display.java:5896) at org.eclipse.swt.internal.cocoa.OS.objc_msgSend_bool(Native Method) at org.eclipse.swt.internal.cocoa.NSRunLoop.runMode(NSRunLoop.java:42) at org.eclipse.swt.widgets.Display.sleep(Display.java:4680) Since the availability of OS X 10.10 preview this became the most often reported bug for us. Please fix in 4.5! Can you please provide the SWT version number/build number along with the stack traces to figure out where the NPE is coming from? (In reply to Thomas Singer from comment #6) > Here are a couple of more similar stacktraces: These stacktraces are from SWT 4.4.0 (version.txt shows "version 4.427"). (In reply to Thomas Singer from comment #9) > (In reply to Thomas Singer from comment #6) > > Here are a couple of more similar stacktraces: > > These stacktraces are from SWT 4.4.0 (version.txt shows "version 4.427"). Line 2118 is - context = graphicsContext.id; That means NSGraphicsContext.currentContext() is returning null in some cases. But, from the documentation, it looks like it should return a non-null value. As noted in comment 3, I am observing these NPEs only where I want to measure the size of Widget, when the context is not a paint event or some other OS generated event. In many of the stack traces posted here, the situation seems to be similar... but not all of them (comment 1). Still maybe its worth exploring? It seems that under El Capitan, the error has become much more frequent. I've upgraded my Mac to 10.11, downloaded Eclipse Mars, and the after a few minutes of use, Eclipse asked me whether I wanted to take part in the user error reporting. It turned out that it hit this bug. So it is Eclipse itself which is also affected. It happens in the Tree widget when it wants to measure items (SWT.MeasureItem event, if memory serves). This is exactly the same stack trace that we get with out application. Created attachment 257162 [details]
Sample to reproduce
I've attached a sample to reproduce. Just hover the mouse over one (too narrow) cell on OS X 10.11 and it crashs. Are you able to reproduce this NPE using the sent snippet? (In reply to Thomas Singer from comment #15) > Are you able to reproduce this NPE using the sent snippet? Thanks for the snippet. I'm able to reproduce the NPE. It's interesting to see that the same code NSGraphicsContext.currentContext() that was working in OSX 10.10 & below, is failing in OSX 10.11. I'm currently investigating the problem. *** Bug 479007 has been marked as a duplicate of this bug. *** FWIW, this issue is actually looks big. I've seen this error on Trees: https://dev.eclipse.org/recommenders/committers/confess/#/problems/56267294e4b0b60733e13bf1/details https://dev.eclipse.org/recommenders/committers/confess/#/problems/5606f786e4b0d155bf9793d7/details https://dev.eclipse.org/recommenders/committers/confess/#/problems/56254703e4b0be0032730160/details I'm yet not able to express this in a comprehensive search query but if you are looking for other examples you may find the query below helpful (subjects should be NullPointerException in org.eclipse.swt.widgets.Control.internal_new_GC) https://dev.eclipse.org/recommenders/committers/confess/#/problems/search?frame=org.eclipse.swt.widgets.Control.internal_new_GC Yes, this is currently our most serious bug on OS X 10.11 in SWT with SmartGit/SmartSVN - we've already got ~40,000 reports. *** Bug 480816 has been marked as a duplicate of this bug. *** (In reply to Thomas Singer from comment #19) > Yes, this is currently our most serious bug on OS X 10.11 in SWT with > SmartGit/SmartSVN - we've already got ~40,000 reports. I noticed in recent SmartSVN versions this error does not occur anymore. Did you find a solution to this problem? We're currently facing the very same problems with our SWT based applications. In our products we catch the exceptions with Table.sendMeasureItem and Tree.sendMeasureItem and ignore them silently. (In reply to Thomas Singer from comment #22) > In our products we catch the exceptions with Table.sendMeasureItem and > Tree.sendMeasureItem and ignore them silently. Can you please describe how you catch those exceptions? (In reply to Sven Wende from comment #23) > (In reply to Thomas Singer from comment #22) > > In our products we catch the exceptions with Table.sendMeasureItem and > > Tree.sendMeasureItem and ignore them silently. > > Can you please describe how you catch those exceptions? With Thread.setDefaultUncaughtExceptionHandler() you can set an own instance of Thread.UncaughtExceptionHandler. This will be used by SWT (and AWT). Then just either ignore the exception or otherwise process it, e.g. log. Created attachment 258355 [details]
patch
NSGraphicsContext currentContext() can return null when called from a
non-drawing method, for eg, Table.cellSize(). The fix to is to check if
the context returned is valid, if not we create a new context using
NSGraphicsContext.graphicsContextWithWindow.
The patch works with the above snippet. I'm still testing the different cases.
Pushed above patch to master for 4.5M4 --> http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=7bbf8d4559e0a792751c656ac72cdd3326f6a324 (In reply to Lakshmi Shanmugam from comment #26) > Pushed above patch to master for 4.5M4 --> Sorry, I meant pushed patch to master for 4.6M4 Verified in I20151207-2000 Pushed to R4_5_maintenance branch -- http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?h=R4_5_maintenance&id=3e30fac11a11e522e98cb140095cc4e29c2d4371 Verified in M20160120-1000. *** Bug 481821 has been marked as a duplicate of this bug. *** *** Bug 486962 has been marked as a duplicate of this bug. *** We've got NPEs reported because the following new line in internal_new_GC() graphicsContext = NSGraphicsContext.graphicsContextWithWindow (window); returns null, so the next line's graphicsContext.graphicsPort() will fail. (In reply to Thomas Singer from comment #33) > We've got NPEs reported because the following new line in internal_new_GC() > > graphicsContext = NSGraphicsContext.graphicsContextWithWindow (window); > > returns null, so the next line's graphicsContext.graphicsPort() will fail. Can you attach the stacktrace and build-id on which the problem occurs? It was reported against the latest SmartGit 7.1.0 release which uses SWT 4.610 according to version.txt. Here is the stacktrace: java.lang.NullPointerException at org.eclipse.swt.widgets.Control.internal_new_GC(Control.java:2174) at org.eclipse.swt.graphics.GC.<init>(GC.java:174) at org.eclipse.swt.graphics.GC.<init>(GC.java:135) at org.eclipse.swt.custom.StyledTextRenderer.setFont(StyledTextRenderer.java:1108) at org.eclipse.swt.custom.StyledText.<init>(StyledText.java:1252) ... (In reply to Thomas Singer from comment #35) > It was reported against the latest SmartGit 7.1.0 release which uses SWT > 4.610 according to version.txt. Here is the stacktrace: > > java.lang.NullPointerException > at org.eclipse.swt.widgets.Control.internal_new_GC(Control.java:2174) > at org.eclipse.swt.graphics.GC.<init>(GC.java:174) > at org.eclipse.swt.graphics.GC.<init>(GC.java:135) > at > org.eclipse.swt.custom.StyledTextRenderer.setFont(StyledTextRenderer.java: > 1108) > at org.eclipse.swt.custom.StyledText.<init>(StyledText.java:1252) > ... I looked at the complete list of the reported errors for this problem [1]. The NPE happens at 2 places. One is as shown in comment#6 (when MeasureItem is sent). Other is similar to comment#1 (in new GC constructor). See -- https://dev.eclipse.org/recommenders/committers/confess/#/problems/55cc3af7e4b0176300a7b2b0/ -- https://dev.eclipse.org/recommenders/committers/confess/#/problems/56434cf9e4b0c02da2cfeb42/ The fix in this bug has addressed the first problem, NPE when MeasureItem event is sent. NPE in GC constructor happens in some cases and that needs to be addressed. I've opened a new bug to track this - Bug 487922. [1] https://dev.eclipse.org/recommenders/committers/confess/#/problems/?stackTraceElement=org.eclipse.swt.widgets.Control.internal_new_GC&project=swt&os=macosx&projection=overview&page=0&size=20&sort=modifiedOn,desc *** Bug 483379 has been marked as a duplicate of this bug. *** *** Bug 487922 has been marked as a duplicate of this bug. *** *** Bug 578502 has been marked as a duplicate of this bug. *** |