eclipse-platform / eclipse.platform.ui

Eclipse Platform
https://projects.eclipse.org/projects/eclipse.platform
Eclipse Public License 2.0
81 stars 190 forks source link

NullPointerException when using #org-eclipse-ui-workbench-DARK_FOREGROUND with the * selector #1049

Open meraedit opened 1 year ago

meraedit commented 1 year ago

When using the following rule in our e4 dark theme extension * { background-color: '#org-eclipse-ui-workbench-DARK_BACKGROUND'; color: '#org-eclipse-ui-workbench-DARK_FOREGROUND'; } the background color is applied just fine because a converter is used for the preference.

However, the foreground preference ends up as org_eclipse_ui_workbench_DARK_FOREGROUND which is not a SWT constant. So the following exception happens:
java.lang.NullPointerException: Cannot read field "rgb" because the return value of "org.eclipse.e4.ui.css.swt.helpers.CSSSWTColorHelper.getRGBA(org.w3c.dom.css.CSSValue)" is null at org.eclipse.e4.ui.css.swt.properties.definition.CSSPropertyColorDefinitionHandler.applyCSSProperty(CSSPropertyColorDefinitionHandler.java:33) at org.eclipse.e4.ui.css.core.impl.engine.AbstractCSSEngine.applyCSSProperty(AbstractCSSEngine.java:746) at org.eclipse.e4.ui.css.core.impl.engine.AbstractCSSEngine.applyStyleDeclaration(AbstractCSSEngine.java:552) at org.eclipse.e4.ui.css.core.impl.engine.AbstractCSSEngine.applyStyles(AbstractCSSEngine.java:426) at org.eclipse.e4.ui.css.core.impl.engine.AbstractCSSEngine.applyStyles(AbstractCSSEngine.java:374) at org.eclipse.e4.ui.css.swt.internal.theme.ThemeEngine.applyStyles(ThemeEngine.java:555) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$7.style(PartRenderingEngine.java:1308) at org.eclipse.ui.internal.themes.WorkbenchThemeManager$WorkbenchThemeChangedHandler.overrideAlreadyExistingDefinitions(WorkbenchThemeManager.java:461) at org.eclipse.ui.internal.themes.WorkbenchThemeManager$WorkbenchThemeChangedHandler.handleEvent(WorkbenchThemeManager.java:381) at org.eclipse.e4.ui.services.internal.events.UIEventHandler.lambda$0(UIEventHandler.java:38) at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:183) at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:133) at org.eclipse.swt.widgets.Display.syncExec(Display.java:4785) at org.eclipse.e4.ui.workbench.swt.DisplayUISynchronize.syncExec(DisplayUISynchronize.java:34) at org.eclipse.e4.ui.services.internal.events.UIEventHandler.handleEvent(UIEventHandler.java:38) at org.eclipse.equinox.internal.event.EventHandlerWrapper.handleEvent(EventHandlerWrapper.java:205) at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:203) at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:1) at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:234) at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:151) at org.eclipse.equinox.internal.event.EventAdminImpl.dispatchEvent(EventAdminImpl.java:133) at org.eclipse.equinox.internal.event.EventAdminImpl.sendEvent(EventAdminImpl.java:75) at org.eclipse.equinox.internal.event.EventComponent.sendEvent(EventComponent.java:44) at org.eclipse.e4.ui.css.swt.internal.theme.ThemeEngine.sendThemeChangeEvent(ThemeEngine.java:527) at org.eclipse.e4.ui.css.swt.internal.theme.ThemeEngine.setTheme(ThemeEngine.java:506) at org.eclipse.e4.ui.css.swt.internal.theme.ThemeEngine.setTheme(ThemeEngine.java:436) at org.eclipse.e4.ui.css.swt.internal.theme.ThemeEngine.setTheme(ThemeEngine.java:428) at org.eclipse.e4.ui.css.swt.internal.theme.ThemeEngine.restore(ThemeEngine.java:624) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.setCSSTheme(PartRenderingEngine.java:1417) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.initializeStyling(PartRenderingEngine.java:1324) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1050) at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1046) at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:155) at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:643) at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338) at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:550) at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:171) at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:152) at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:203) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:136) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:402) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:255) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.base/java.lang.reflect.Method.invoke(Unknown Source) at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:659) at org.eclipse.equinox.launcher.Main.basicRun(Main.java:596) at org.eclipse.equinox.launcher.Main.run(Main.java:1467)

jukzi commented 1 year ago

could you try this patch to get more information whats going on?

diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTColorHelper.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTColorHelper.java
index 0911217..c31d40d 100644
--- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTColorHelper.java
+++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTColorHelper.java
@@ -185,7 +185,14 @@

    public static RGBA getRGBA(CSSValue value) {
        if (value.getCssValueType() != CSSValue.CSS_PRIMITIVE_VALUE) {
-           return null;
+           String cssText;
+           try {
+               cssText = value.getCssText();
+           } catch (UnsupportedOperationException e) {
+               cssText = value.getClass().getTypeName();
+           }
+           throw new RuntimeException(
+                   "Color type is not CSS_PRIMITIVE_VALUE:" + cssText + " but: " + value.getCssValueType());
        }
        return getRGBA((CSSPrimitiveValue) value);
    }
meraedit commented 1 year ago

value.getCssText() is #org-eclipse-ui-workbench-DARK_FOREGROUND and value.getCssValueType() is 1

jukzi commented 1 year ago

no idea.

meraedit commented 1 year ago

value.getCssValueType() is 1 so == CSSValue.CSS_PRIMITIVE_VALUE so it wouldn't get into the if

meraedit commented 1 year ago

org-eclipse-ui-workbench-DARK_FOREGROUND is converted to org_eclipse_ui_workbench_DARK_FOREGROUND in org.eclipse.e4.ui.css.swt.helpers.CSSSWTColorHelper.getRGBA(String)

and then in the process method of the same class, it tries to match it to a SWT constant. But org_eclipse_ui_workbench_DARK_FOREGROUND is not a field of the SWT class, so it returns null.

jukzi commented 1 year ago

please propose a fix with a Pull Request-