From 584b6cdccf14d47235fcdf6fe40197ee5983b85b Mon Sep 17 00:00:00 2001 From: David McKnight Date: Mon, 18 Aug 2008 20:19:55 +0000 Subject: [PATCH] [243263] NPE on expanding a filter - regressed back to original wrong window code since: 1) we should be returning null when on the wrong thread 2) several consumers don't expect null so for 3.0.1 we should keep the original behaviour --- .../org/eclipse/rse/ui/SystemBasePlugin.java | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/SystemBasePlugin.java b/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/SystemBasePlugin.java index ef695434758..c43b3b4a76e 100644 --- a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/SystemBasePlugin.java +++ b/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/SystemBasePlugin.java @@ -116,19 +116,24 @@ public abstract class SystemBasePlugin extends AbstractUIPlugin // otherwise, get a list of all the windows, and simply return the first one // KM: why do we need this?? else { - final IWorkbench workbench = wb; + // for bug 244454, this ends up returning the wrong window + // the correct solution involves: + // - returning null when called from a non-UI thread + // - making sure that callers handle and understand that + // - null may be returned + // + // but for now (in 3.0.1) we're leaving this because + // there are several callers that don't expect null and + // will fail if we make the change now + // + IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows(); - // do this in a runnable so we can get the right window on the main thread - class GetActiveWindow implements Runnable { - public IWorkbenchWindow _activeWindow = null; - public void run() - { - _activeWindow = workbench.getActiveWorkbenchWindow(); - } + if (windows != null && windows.length > 0) { + return windows[0]; + } + else { + return null; } - GetActiveWindow runnable = new GetActiveWindow(); - wb.getDisplay().syncExec(runnable); - return runnable._activeWindow; } }