Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 487922 - [Cocoa] OS X: NPE in Control.internal_new_GC
Summary: [Cocoa] OS X: NPE in Control.internal_new_GC
Status: CLOSED DUPLICATE of bug 434393
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.4   Edit
Hardware: PC Mac OS X
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 482454 494879 516837
  Show dependency tree
 
Reported: 2016-02-17 05:08 EST by Lakshmi P Shanmugam CLA
Modified: 2019-05-16 13:27 EDT (History)
23 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Lakshmi P Shanmugam CLA 2016-02-17 05:08:27 EST
+++ This bug was initially created as a clone of Bug #434393 +++

We've got following exception sent by a user of our SWT-based application (SWT version 4.333, Mac OS X 10.9.2, java 1.7.0_45):

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 com.syntevo.q.swt.QTabFolder.updateItems(SourceFile:806)
...

The 2134th line of Control.java reads:

		NSGraphicsContext flippedContext = NSGraphicsContext.graphicsContextWithGraphicsPort(graphicsContext.graphicsPort(), true);

so it looks like under certain conditions graphicsContext might be null.
Comment 1 Lakshmi P Shanmugam CLA 2016-02-17 05:12:12 EST
NPE occurs when GC constructor is called in some cases.
For ex:  https://dev.eclipse.org/recommenders/committers/confess/#/problems/55cc3af7e4b0176300a7b2b0/
-- https://dev.eclipse.org/recommenders/committers/confess/#/problems/56434cf9e4b0c02da2cfeb42/

From https://bugs.eclipse.org/bugs/show_bug.cgi?id=434393#c35
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)
...
Comment 2 Larry LeBron CLA 2016-03-02 15:02:48 EST
I consistently get this on osx.

Context:

I am working on an XText project, and test it by launching an Eclipse runtime instance from my main eclipse instance. The error then regularly shows up in the main instance.

Please contact me if I can help get you any data.

Here is the most recent stack trace:

!ENTRY org.eclipse.ui 4 0 2016-03-02 11:58:01.754
!MESSAGE Unhandled event loop exception
!STACK 0
java.lang.NullPointerException
	at org.eclipse.swt.widgets.Control.internal_new_GC(Control.java:2124)
	at org.eclipse.swt.graphics.GC.cocoa_new(GC.java:210)
	at org.eclipse.swt.widgets.Tree.sendMeasureItem(Tree.java:2596)
	at org.eclipse.swt.widgets.Tree.cellSize(Tree.java:288)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:5582)
	at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper_stret(Native Method)
	at org.eclipse.swt.widgets.Widget.expansionFrameWithFrame_inView(Widget.java:814)
	at org.eclipse.swt.widgets.Tree.expansionFrameWithFrame_inView(Tree.java:1274)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:5961)
	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:4740)
	at org.eclipse.ui.application.WorkbenchAdvisor.eventLoopIdle(WorkbenchAdvisor.java:368)
	at org.eclipse.ui.internal.ide.application.IDEWorkbenchAdvisor.eventLoopIdle(IDEWorkbenchAdvisor.java:858)
	at org.eclipse.ui.internal.Workbench$3.eventLoopIdle(Workbench.java:517)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1132)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1018)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:156)
	at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:654)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:598)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:139)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:669)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:608)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1515)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1488)
Comment 3 Larry LeBron CLA 2016-03-02 15:04:18 EST
Adding version and os info:

Eclipse:
Version: Mars.1 (4.5.1)
Build id: M20150904-0015

OSX 10.11.2
Comment 4 Lakshmi P Shanmugam CLA 2016-03-03 01:42:14 EST
(In reply to Larry LeBron from comment #2)
> I consistently get this on osx.
> 
> Here is the most recent stack trace:
> 
> !ENTRY org.eclipse.ui 4 0 2016-03-02 11:58:01.754
> !MESSAGE Unhandled event loop exception
> !STACK 0
> java.lang.NullPointerException
> 	at org.eclipse.swt.widgets.Control.internal_new_GC(Control.java:2124)
> 	at org.eclipse.swt.graphics.GC.cocoa_new(GC.java:210)
> 	at org.eclipse.swt.widgets.Tree.sendMeasureItem(Tree.java:2596)
> 	at org.eclipse.swt.widgets.Tree.cellSize(Tree.java:288)
> 	at org.eclipse.swt.widgets.Display.windowProc(Display.java:5582)
> 	at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper_stret(Native Method)
> 	at
> org.eclipse.swt.widgets.Widget.expansionFrameWithFrame_inView(Widget.java:
> 814)
This problem has been fixed in Eclipse 4.5.2 through bug 434393. Please try with the latest 4.5.2 version.
Comment 5 Thomas Singer CLA 2016-12-10 06:17:16 EST
Can this bug be closed?
Comment 6 Larry LeBron CLA 2016-12-10 11:38:44 EST
I am no longer seeing the issue.
Comment 7 Marc-André Laperle CLA 2017-05-17 14:36:22 EDT

*** This bug has been marked as a duplicate of bug 434393 ***
Comment 8 Thomas Singer CLA 2017-07-19 04:27:29 EDT
We've got this stacktrace again with SWT version 4.756:

java.lang.NullPointerException
	at org.eclipse.swt.widgets.Control.internal_new_GC(Control.java:2176)
	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:1118)
	at org.eclipse.swt.custom.StyledText.<init>(StyledText.java:1256)

The code reads:

graphicsContext = NSGraphicsContext.graphicsContextWithWindow (window);
NSGraphicsContext flippedContext = NSGraphicsContext.graphicsContextWithGraphicsPort(graphicsContext.graphicsPort(), true);
graphicsContext = flippedContext;

where graphicsContext seems to be null which is possible in NSGraphicsContext.graphicsContextWithWindow().
Comment 9 Andreas Buchen CLA 2019-02-19 03:04:13 EST
Users (still) report it with SWT version 4.919:

java.lang.NullPointerException
	at org.eclipse.swt.widgets.Control.internal_new_GC(Control.java:2180)
	at org.eclipse.swt.graphics.GC.<init>(GC.java:177)
	at org.eclipse.swt.graphics.GC.<init>(GC.java:138)
	at org.eclipse.swt.custom.CTabFolder.updateTabHeight(CTabFolder.java:3810)

Happens in the same code fragment as reported in comment #8.
Comment 10 Till Brychcy CLA 2019-05-16 13:27:16 EDT
(In reply to Andreas Buchen from comment #9)
> Users (still) report it with SWT version 4.919:
> 
> java.lang.NullPointerException
> 	at org.eclipse.swt.widgets.Control.internal_new_GC(Control.java:2180)
> 	at org.eclipse.swt.graphics.GC.<init>(GC.java:177)
> 	at org.eclipse.swt.graphics.GC.<init>(GC.java:138)
> 	at org.eclipse.swt.custom.CTabFolder.updateTabHeight(CTabFolder.java:3810)
> 

This is probably bug 547399