diff --git a/bundles/org.eclipse.core.jobs/src/org/eclipse/core/internal/jobs/JobManager.java b/bundles/org.eclipse.core.jobs/src/org/eclipse/core/internal/jobs/JobManager.java index 9c6ec9abc..0f7670380 100644 --- a/bundles/org.eclipse.core.jobs/src/org/eclipse/core/internal/jobs/JobManager.java +++ b/bundles/org.eclipse.core.jobs/src/org/eclipse/core/internal/jobs/JobManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2020 IBM Corporation and others. + * Copyright (c) 2003, 2022 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -20,7 +20,8 @@ * Jan Koehnlein - Fix for bug 60964 (454698) * Terry Parker - Bug 457504, Publish a job group's final status to IJobChangeListeners * Xored Software Inc - Fix for bug 550738 - * Christoph Laeubrich - remove deprecated API + * Christoph Laeubrich - remove deprecated API + * - Issue #40 - UI freezes when a ThreadJob is waiting to run in the UI Thread *******************************************************************************/ package org.eclipse.core.internal.jobs; @@ -1100,19 +1101,17 @@ boolean join(InternalJobGroup jobGroup, long timeout, IProgressMonitor monitor) } /** - * Returns a non-null progress monitor instance. If the monitor is null, - * returns the default monitor supplied by the progress provider, or a + * Returns a non-null progress monitor instance. If a progress provider is + * given, returns the monitor for this supplied by the progress provider, or a * NullProgressMonitor if no default monitor is available. */ private IProgressMonitor monitorFor(IProgressMonitor monitor) { - if (monitor == null || (monitor instanceof NullProgressMonitor)) { - if (progressProvider != null) { - try { - monitor = progressProvider.getDefaultMonitor(); - } catch (Exception e) { - String msg = NLS.bind(JobMessages.meta_pluginProblems, JobManager.PI_JOBS); - RuntimeLog.log(new Status(IStatus.ERROR, JobManager.PI_JOBS, JobManager.PLUGIN_ERROR, msg, e)); - } + if (progressProvider != null) { + try { + return Objects.requireNonNull(progressProvider.monitorFor(monitor), "ProgressProvider returned null!"); //$NON-NLS-1$ + } catch (Exception e) { + String msg = NLS.bind(JobMessages.meta_pluginProblems, JobManager.PI_JOBS); + RuntimeLog.log(new Status(IStatus.ERROR, JobManager.PI_JOBS, JobManager.PLUGIN_ERROR, msg, e)); } } diff --git a/bundles/org.eclipse.core.jobs/src/org/eclipse/core/runtime/jobs/ProgressProvider.java b/bundles/org.eclipse.core.jobs/src/org/eclipse/core/runtime/jobs/ProgressProvider.java index a2239cef3..0136eb68f 100644 --- a/bundles/org.eclipse.core.jobs/src/org/eclipse/core/runtime/jobs/ProgressProvider.java +++ b/bundles/org.eclipse.core.jobs/src/org/eclipse/core/runtime/jobs/ProgressProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2012 IBM Corporation and others. + * Copyright (c) 2003, 2022 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -10,6 +10,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Christoph Läubrich - Issue #40 - UI freezes when a ThreadJob is waiting to run in the UI Thread *******************************************************************************/ package org.eclipse.core.runtime.jobs; @@ -96,4 +97,24 @@ public IProgressMonitor createMonitor(Job job, IProgressMonitor group, int ticks public IProgressMonitor getDefaultMonitor() { return new NullProgressMonitor(); } + + /** + * Returns a (possibly wrapped) progress monitor to use when running the job. + *

+ * This default implementation returns ProgressProvider#getDefaultMonitor() when + * the monitor is null or an instance of + * {@link NullProgressMonitor} and the passed instance otherwise. Subclasses may + * override. + * + * @param monitor the monitor to wrap, might be null + * @return a progress monitor, either wrapped or the passed instance but never + * null + * @since 3.13 + */ + public IProgressMonitor monitorFor(IProgressMonitor monitor) { + if (monitor == null || monitor instanceof NullProgressMonitor) { + return getDefaultMonitor(); + } + return monitor; + } }