Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 540081

Summary: [Cocoa][10.14]NPE for skinned shell-toolbar in dark mode
Product: [Eclipse Project] Platform Reporter: Thomas Singer <eclipse>
Component: SWTAssignee: Platform-SWT-Inbox <platform-swt-inbox>
Status: VERIFIED FIXED QA Contact:
Severity: critical    
Priority: P3 CC: lshanmug, ned.twigg, register.eclipse, romain.castell, ts-swt
Version: 4.9   
Target Milestone: 4.13 M1   
Hardware: Macintosh   
OS: Mac OS X   
See Also: https://bugs.eclipse.org/bugs/show_bug.cgi?id=543889
https://bugs.eclipse.org/bugs/show_bug.cgi?id=547399
Whiteboard:
Attachments:
Description Flags
Snippet to crash without .app bundle none

Description Thomas Singer CLA 2018-10-12 08:26:11 EDT
Running this tiny snippet on macOS 10.14 switched to dark mode

public static void main(String[] args) {
    final Display display = new Display();

    final Shell shell = new Shell(display);
    final ToolBar toolBar = shell.getToolBar();
    toolBar.setData(SWT.SKIN_CLASS, "shell");

    shell.setSize(300, 200);
    shell.open();

    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }

    display.dispose();
}

produces following stacktrace:

java.lang.NullPointerException
	at org.eclipse.swt.widgets.Composite._getChildren(Composite.java:99)
	at org.eclipse.swt.widgets.Composite.reskinChildren(Composite.java:979)
	at org.eclipse.swt.widgets.ToolBar.reskinChildren(ToolBar.java:716)
	at org.eclipse.swt.widgets.Widget.reskin(Widget.java:423)
	at org.eclipse.swt.widgets.Widget.setData(Widget.java:1704)
Comment 1 Thomas Singer CLA 2018-10-12 09:08:57 EDT
Note, that the application needs the NSRequireAquaSystemApperance to false.
Comment 2 Romain Castell CLA 2019-02-06 11:41:46 EST
Almost certainly related exception reported when adding:

    <key>NSRequiresAquaSystemAppearance</key><false/>

to Info.plist file from Eclipse 2018-12 (4.10.0)

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.widgets.Tree.setScrollWidth(Tree.java:3172)
	at org.eclipse.swt.widgets.TreeItem.setImage(TreeItem.java:1414)
	at org.eclipse.jface.viewers.TreeViewerRow.setImage(TreeViewerRow.java:113)
	at org.eclipse.jface.viewers.ViewerCell.setImage(ViewerCell.java:172)
	at org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.update(DelegatingStyledCellLabelProvider.java:124)
	at org.eclipse.jface.viewers.DecoratingStyledCellLabelProvider.update(DecoratingStyledCellLabelProvider.java:134)
	at org.eclipse.jface.viewers.ViewerColumn.refresh(ViewerColumn.java:144)
	at org.eclipse.jface.viewers.AbstractTreeViewer.doUpdateItem(AbstractTreeViewer.java:946)
	at org.eclipse.jface.viewers.AbstractTreeViewer$UpdateItemSafeRunnable.run(AbstractTreeViewer.java:120)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
	at org.eclipse.ui.internal.JFaceUtil.lambda$0(JFaceUtil.java:47)
	at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:176)
	at org.eclipse.jface.viewers.AbstractTreeViewer.doUpdateItem(AbstractTreeViewer.java:1025)
	at org.eclipse.ui.navigator.CommonViewer.doUpdateItem(CommonViewer.java:404)
	at org.eclipse.ui.internal.navigator.resources.ResourceToItemsMapper.updateItem(ResourceToItemsMapper.java:153)
	at org.eclipse.ui.internal.navigator.resources.ResourceToItemsMapper.objectChanged(ResourceToItemsMapper.java:141)
	at org.eclipse.ui.navigator.CommonViewer.handleLabelProviderChanged(CommonViewer.java:228)
	at org.eclipse.jface.viewers.ContentViewer$1.labelProviderChanged(ContentViewer.java:102)
	at org.eclipse.jface.viewers.BaseLabelProvider$1.run(BaseLabelProvider.java:75)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
	at org.eclipse.ui.internal.JFaceUtil.lambda$0(JFaceUtil.java:47)
	at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:176)
	at org.eclipse.jface.viewers.BaseLabelProvider.fireLabelProviderChanged(BaseLabelProvider.java:72)
	at org.eclipse.jface.viewers.DecoratingStyledCellLabelProvider.lambda$0(DecoratingStyledCellLabelProvider.java:78)
	at org.eclipse.ui.internal.decorators.DecoratorManager$1.run(DecoratorManager.java:377)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
	at org.eclipse.ui.internal.decorators.DecoratorManager.fireListener(DecoratorManager.java:374)
	at org.eclipse.ui.internal.decorators.DecorationScheduler$3.runInUIThread(DecorationScheduler.java:488)
	at org.eclipse.ui.progress.UIJob.lambda$0(UIJob.java:98)
	at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:40)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:185)
	at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4095)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3762)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1173)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:339)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1062)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:156)
	at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:636)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:339)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:563)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:151)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:155)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:203)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:137)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:107)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:400)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:255)
	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:498)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:659)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:595)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1501)
Comment 3 Till Brychcy CLA 2019-02-07 03:20:04 EST
The experimental gerrit https://git.eclipse.org/r/#/c/132638/ I created for bug 540357 fixes the NPEs, but setting NSRequireAquaSystemApperance also seems to activate a new cocoa API level, where views are layer backed, which leads to redrawing issues

Sooner or later we will have to adapt to this new API behavior anyway, but for now Lakshmi has found a way for programmatically enabling dark mode that doesn't trigger this (see bug 543889)
Comment 4 Thomas Singer CLA 2019-04-29 10:05:50 EDT
This exception also happens with SWT v4926r16 (ce086f19) and having set org.eclipse.swt.display.useSystemTheme=true (without setting <key>NSRequiresAquaSystemAppearance</key><false/>).
Comment 5 Lakshmi P Shanmugam CLA 2019-05-16 06:54:59 EDT
(In reply to Thomas Singer from comment #4)
> This exception also happens with SWT v4926r16 (ce086f19) and having set
> org.eclipse.swt.display.useSystemTheme=true (without setting
> <key>NSRequiresAquaSystemAppearance</key><false/>).

Can you please check if https://git.eclipse.org/r/#/c/132638/ fixes the NPEs for you?
Comment 6 Thomas Singer CLA 2019-05-16 09:00:11 EDT
If I've didn't make something wrong, this pull request does NOT fix the toolbar related NPE.
Comment 7 Till Brychcy CLA 2019-05-16 09:20:50 EDT
Comment #0 is a different issue not related to graphicsContext.

My comment #3 was about comment #2
Comment 8 Till Brychcy CLA 2019-05-16 13:08:32 EDT
I've create bug 547399 for the issue of NPE in Display.internal_new_GC
Comment 9 Thomas Singer CLA 2019-05-22 08:07:45 EDT
Created attachment 278694 [details]
Snippet to crash without .app bundle
Comment 10 Lakshmi P Shanmugam CLA 2019-05-22 08:14:54 EDT
Are you running with Java 11 or newer? This looks duplicate of Bug 546159.
Comment 11 Thomas Singer CLA 2019-05-22 09:16:29 EDT
Now, plain ol' Java 8.
Comment 12 Lakshmi P Shanmugam CLA 2019-06-04 05:20:17 EDT
(In reply to Lakshmi Shanmugam from comment #10)
> Are you running with Java 11 or newer? This looks duplicate of Bug 546159.

Patch in Bug 546159 fixes the issue in the snippet in this bug as well.
Comment 13 Lakshmi P Shanmugam CLA 2019-07-15 07:24:14 EDT
This should be fixed now (by fix for Bug 546159)
Comment 14 Lakshmi P Shanmugam CLA 2019-07-15 07:25:21 EDT
The problem is not related to Bug 540357.