Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Exception using IThemeManager#getDefaultTheme() from non-UI thread #722

Merged
merged 2 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion org.eclipse.tm4e.core.tests/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Bundle-SymbolicName: org.eclipse.tm4e.core.tests;singleton:=true
Bundle-Version: 0.10.2.qualifier
Bundle-Version: 0.10.3.qualifier
Require-Bundle: org.apache.batik.css;resolution:=optional,
org.apache.batik.util;resolution:=optional,
com.google.gson;resolution:=optional,
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.tm4e.core.tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.eclipse</groupId>
<artifactId>org.eclipse.tm4e</artifactId>
<version>0.10.2-SNAPSHOT</version>
<version>0.10.3-SNAPSHOT</version>
</parent>

<artifactId>org.eclipse.tm4e.core.tests</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.tm4e.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Bundle-SymbolicName: org.eclipse.tm4e.core
Bundle-Version: 0.10.2.qualifier
Bundle-Version: 0.10.3.qualifier
Require-Bundle: com.google.gson;bundle-version="[2.10.1,3.0.0)",
org.apache.batik.css;bundle-version="[1.16.0,2.0.0)";resolution:=optional,
org.apache.batik.util;bundle-version="[1.16.0,2.0.0)";resolution:=optional,
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.tm4e.core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.eclipse</groupId>
<artifactId>org.eclipse.tm4e</artifactId>
<version>0.10.2-SNAPSHOT</version>
<version>0.10.3-SNAPSHOT</version>
</parent>

<artifactId>org.eclipse.tm4e.core</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.tm4e.feature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<feature
id="org.eclipse.tm4e.feature"
label="%featureName"
version="0.10.2.qualifier"
version="0.10.3.qualifier"
provider-name="%featureProvider"
license-feature="org.eclipse.license"
license-feature-version="0.0.0">
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.tm4e.feature/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.eclipse</groupId>
<artifactId>org.eclipse.tm4e</artifactId>
<version>0.10.2-SNAPSHOT</version>
<version>0.10.3-SNAPSHOT</version>
</parent>

<artifactId>org.eclipse.tm4e.feature</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.tm4e.language_pack.feature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<feature
id="org.eclipse.tm4e.language_pack.feature"
label="%featureName"
version="0.10.2.qualifier"
version="0.10.3.qualifier"
provider-name="%featureProvider"
license-feature="org.eclipse.license"
license-feature-version="0.0.0">
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.tm4e.language_pack.feature/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.eclipse</groupId>
<artifactId>org.eclipse.tm4e</artifactId>
<version>0.10.2-SNAPSHOT</version>
<version>0.10.3-SNAPSHOT</version>
</parent>

<artifactId>org.eclipse.tm4e.language_pack.feature</artifactId>
Expand Down
8 changes: 4 additions & 4 deletions org.eclipse.tm4e.language_pack/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Bundle-SymbolicName: org.eclipse.tm4e.language_pack;singleton:=true
Bundle-Version: 0.10.2.qualifier
Require-Bundle: org.eclipse.tm4e.ui;bundle-version="0.10.2",
org.eclipse.tm4e.registry;bundle-version="0.10.2",
org.eclipse.tm4e.languageconfiguration;bundle-version="0.10.2",
Bundle-Version: 0.10.3.qualifier
Require-Bundle: org.eclipse.tm4e.ui;bundle-version="0.10.3",
org.eclipse.tm4e.registry;bundle-version="0.10.3",
org.eclipse.tm4e.languageconfiguration;bundle-version="0.10.3",
org.eclipse.ui.editors;bundle-version="[3.3.0,4.0.0)",
org.eclipse.ui.genericeditor;bundle-version="[1.0.0,2.0.0)",
org.eclipse.core.contenttype;bundle-version="[3.2.0,4.0.0)"
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.tm4e.language_pack/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.eclipse</groupId>
<artifactId>org.eclipse.tm4e</artifactId>
<version>0.10.2-SNAPSHOT</version>
<version>0.10.3-SNAPSHOT</version>
</parent>

<artifactId>org.eclipse.tm4e.language_pack</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.tm4e.language_pack/updater/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>org.eclipse</groupId>
<artifactId>org.eclipse.tm4e</artifactId>
<version>0.10.2-SNAPSHOT</version>
<version>0.10.3-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Tests for TM4E language configuration support
Bundle-SymbolicName: org.eclipse.tm4e.languageconfiguration.tests;singleton:=true
Bundle-Version: 0.10.2.qualifier
Bundle-Version: 0.10.3.qualifier
Bundle-Vendor: Eclipse TM4E
Automatic-Module-Name: org.eclipse.tm4e.languageconfiguration.tests
Bundle-RequiredExecutionEnvironment: JavaSE-17
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.tm4e.languageconfiguration.tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.eclipse</groupId>
<artifactId>org.eclipse.tm4e</artifactId>
<version>0.10.2-SNAPSHOT</version>
<version>0.10.3-SNAPSHOT</version>
</parent>

<artifactId>org.eclipse.tm4e.languageconfiguration.tests</artifactId>
Expand Down
8 changes: 4 additions & 4 deletions org.eclipse.tm4e.languageconfiguration/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Bundle-SymbolicName: org.eclipse.tm4e.languageconfiguration;singleton:=true
Bundle-Version: 0.10.2.qualifier
Bundle-Version: 0.10.3.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-17
Require-Bundle: org.eclipse.core.expressions,
org.eclipse.core.filebuffers,
Expand All @@ -17,9 +17,9 @@ Require-Bundle: org.eclipse.core.expressions,
org.eclipse.ui.genericeditor,
org.eclipse.ui.ide,
org.eclipse.e4.ui.css.swt.theme,
org.eclipse.tm4e.registry;bundle-version="0.10.2",
org.eclipse.tm4e.core;bundle-version="0.10.2",
org.eclipse.tm4e.ui;bundle-version="0.10.2",
org.eclipse.tm4e.registry;bundle-version="0.10.3",
org.eclipse.tm4e.core;bundle-version="0.10.3",
org.eclipse.tm4e.ui;bundle-version="0.10.3",
com.google.gson;bundle-version="[2.10.1,3.0.0)"
Bundle-Activator: org.eclipse.tm4e.languageconfiguration.LanguageConfigurationPlugin
Export-Package: org.eclipse.tm4e.languageconfiguration,
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.tm4e.languageconfiguration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.eclipse</groupId>
<artifactId>org.eclipse.tm4e</artifactId>
<version>0.10.2-SNAPSHOT</version>
<version>0.10.3-SNAPSHOT</version>
</parent>

<artifactId>org.eclipse.tm4e.languageconfiguration</artifactId>
Expand Down
8 changes: 4 additions & 4 deletions org.eclipse.tm4e.markdown/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Bundle-SymbolicName: org.eclipse.tm4e.markdown;singleton:=true
Bundle-Version: 0.10.2.qualifier
Bundle-Version: 0.10.3.qualifier
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.tm4e.core;bundle-version="0.10.2",
org.eclipse.tm4e.registry;bundle-version="0.10.2",
org.eclipse.tm4e.ui;bundle-version="0.10.2"
org.eclipse.tm4e.core;bundle-version="0.10.3",
org.eclipse.tm4e.registry;bundle-version="0.10.3",
org.eclipse.tm4e.ui;bundle-version="0.10.3"
Bundle-RequiredExecutionEnvironment: JavaSE-17
Export-Package: org.eclipse.tm4e.markdown,
org.eclipse.tm4e.markdown.marked
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.tm4e.markdown/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.eclipse</groupId>
<artifactId>org.eclipse.tm4e</artifactId>
<version>0.10.2-SNAPSHOT</version>
<version>0.10.3-SNAPSHOT</version>
</parent>

<artifactId>org.eclipse.tm4e.markdown</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions org.eclipse.tm4e.registry/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-SymbolicName: org.eclipse.tm4e.registry;singleton:=true
Bundle-Version: 0.10.2.qualifier
Bundle-Version: 0.10.3.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-17
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.equinox.preferences,
org.eclipse.tm4e.core;bundle-version="0.10.2",
org.eclipse.tm4e.core;bundle-version="0.10.3",
com.google.gson;bundle-version="[2.10.1,3.0.0)"
Export-Package: org.eclipse.tm4e.registry
Bundle-Activator: org.eclipse.tm4e.registry.TMEclipseRegistryPlugin
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.tm4e.registry/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.eclipse</groupId>
<artifactId>org.eclipse.tm4e</artifactId>
<version>0.10.2-SNAPSHOT</version>
<version>0.10.3-SNAPSHOT</version>
</parent>

<artifactId>org.eclipse.tm4e.registry</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.tm4e.repository/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.eclipse</groupId>
<artifactId>org.eclipse.tm4e</artifactId>
<version>0.10.2-SNAPSHOT</version>
<version>0.10.3-SNAPSHOT</version>
</parent>

<artifactId>org.eclipse.tm4e.repository</artifactId>
Expand Down
6 changes: 3 additions & 3 deletions org.eclipse.tm4e.samples/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Bundle-SymbolicName: org.eclipse.tm4e.samples;singleton:=true
Bundle-Version: 0.10.2.qualifier
Bundle-Version: 0.10.3.qualifier
Require-Bundle: org.eclipse.jface.text,
org.eclipse.core.runtime,
org.eclipse.ui,
org.eclipse.ui.editors,
org.eclipse.ui.genericeditor;bundle-version="1.0.0";resolution:=optional,
org.eclipse.tm4e.core;bundle-version="0.10.2",
org.eclipse.tm4e.ui;bundle-version="0.10.2"
org.eclipse.tm4e.core;bundle-version="0.10.3",
org.eclipse.tm4e.ui;bundle-version="0.10.3"
Bundle-RequiredExecutionEnvironment: JavaSE-17
Bundle-ActivationPolicy: lazy
Automatic-Module-Name: org.eclipse.tm4e.samples
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.tm4e.samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.eclipse</groupId>
<artifactId>org.eclipse.tm4e</artifactId>
<version>0.10.2-SNAPSHOT</version>
<version>0.10.3-SNAPSHOT</version>
</parent>

<artifactId>org.eclipse.tm4e.samples</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.tm4e.ui.tests/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Bundle-SymbolicName: org.eclipse.tm4e.ui.tests;singleton:=true
Bundle-Version: 0.10.2.qualifier
Bundle-Version: 0.10.3.qualifier
Require-Bundle: org.eclipse.jface.text,
org.eclipse.core.filesystem,
org.eclipse.core.resources,
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.tm4e.ui.tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.eclipse</groupId>
<artifactId>org.eclipse.tm4e</artifactId>
<version>0.10.2-SNAPSHOT</version>
<version>0.10.3-SNAPSHOT</version>
</parent>

<artifactId>org.eclipse.tm4e.ui.tests</artifactId>
Expand Down
6 changes: 3 additions & 3 deletions org.eclipse.tm4e.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Bundle-SymbolicName: org.eclipse.tm4e.ui;singleton:=true
Bundle-Version: 0.10.2.qualifier
Bundle-Version: 0.10.3.qualifier
Require-Bundle: org.eclipse.core.expressions,
org.eclipse.core.filesystem,
org.eclipse.core.resources,
Expand All @@ -16,8 +16,8 @@ Require-Bundle: org.eclipse.core.expressions,
org.eclipse.ui.trace;resolution:=optional,
org.eclipse.ui.workbench.texteditor,
org.eclipse.e4.ui.css.swt.theme,
org.eclipse.tm4e.core;bundle-version="0.10.2",
org.eclipse.tm4e.registry;bundle-version="0.10.2",
org.eclipse.tm4e.core;bundle-version="0.10.3",
org.eclipse.tm4e.registry;bundle-version="0.10.3",
com.google.gson;bundle-version="[2.10.1,3.0.0)"
Bundle-RequiredExecutionEnvironment: JavaSE-17
Export-Package: org.eclipse.tm4e.ui,
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.tm4e.ui/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.eclipse</groupId>
<artifactId>org.eclipse.tm4e</artifactId>
<version>0.10.2-SNAPSHOT</version>
<version>0.10.3-SNAPSHOT</version>
</parent>

<artifactId>org.eclipse.tm4e.ui</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public ITheme[] getThemes() {

@Override
public ITheme getDefaultTheme() {
return getDefaultTheme(UI.isDarkEclipseTheme());
return getDefaultTheme(UI.runSync(UI::isDarkEclipseTheme));
}

@Override
Expand Down Expand Up @@ -87,7 +87,7 @@ public ITheme[] getThemes(final boolean dark) {

@Override
public ITheme getThemeForScope(final String scopeName) {
return getThemeForScope(scopeName, UI.isDarkEclipseTheme());
return getThemeForScope(scopeName, UI.runSync(UI::isDarkEclipseTheme));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@
*******************************************************************************/
package org.eclipse.tm4e.ui.internal.utils;

import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;

import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWTException;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.graphics.Color;
Expand Down Expand Up @@ -176,6 +180,36 @@ public static boolean isDarkEclipseTheme() {
return isDarkColor(shell.getBackground());
}

public static boolean isUIThread() {
return Display.getCurrent() != null;
}

/**
* Runs the given runnable synchronously on the UI thread
*
* @throws SWTException if the {@link Display} has been disposed
*/
public static <T> T runSync(final Supplier<T> runnable) {
if (isUIThread())
return runnable.get();

final var resultRef = new AtomicReference<T>();
final var exRef = new AtomicReference<@Nullable RuntimeException>();
getDisplay().syncExec(() -> {
try {
resultRef.set(runnable.get());
} catch (final RuntimeException ex) {
exRef.set(ex);
}
});

final @Nullable RuntimeException ex = exRef.get();
if (ex != null) {
throw ex;
}
return resultRef.get();
}

private UI() {
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.eclipse</groupId>
<artifactId>org.eclipse.tm4e</artifactId>
<version>0.10.2-SNAPSHOT</version>
<version>0.10.3-SNAPSHOT</version>
<packaging>pom</packaging>

<properties>
Expand Down
Loading