Bug 474946 - Initialization Code must be run asynchronously
authorMartin Schreiber <m.schreiber@bachmann.info>
Mon, 21 Sep 2015 13:30:21 +0000 (15:30 +0200)
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>
Fri, 2 Oct 2015 16:52:44 +0000 (12:52 -0400)
Do the initialization asynchronously. If the service was initialized
during this class gets instantiated, it was re-instantiated and so a
StackOverflowException was produced. Now the initialization is done
asynchronously.

Bug: 474946
Change-Id: I15356c5f6e450d825d4f8615e2fba177409f5894
Signed-off-by: Martin Schreiber <m.schreiber@bachmann.info>
(cherry picked from commit 2cf6b41bd226ac862925b6a61c72ae9e2a867050)

debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/commands/ReverseToggleCommandHandler.java

index 5d27c7b..c12741a 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2011 Ericsson and others.
+ * Copyright (c) 2010, 2015 Ericsson and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -63,18 +63,24 @@ public class ReverseToggleCommandHandler extends DebugCommandHandler implements
     private IDebugContextService fContextService = null;
 
     public ReverseToggleCommandHandler() {
-       IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+       final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        if (window != null) {
-          fContextService = DebugUITools.getDebugContextManager().getContextService(window);
-          if (fContextService != null) {
-                  fContextService.addPostDebugContextListener(this);
-
-                  // This constructor might be called after the launch, so we must refresh here too.
-                  // This can happen if we activate the action set after the launch.
-                  refresh(fContextService.getActiveContext());
-          }
-       }
-    }
+                       window.getShell().getDisplay().asyncExec(new Runnable() {
+
+                               @Override
+                               public void run() {
+                                       fContextService = DebugUITools.getDebugContextManager().getContextService(window);
+                                       if (fContextService != null) {
+                                               fContextService.addPostDebugContextListener(ReverseToggleCommandHandler.this);
+
+                                               // This constructor might be called after the launch, so we must refresh here too.
+                                               // This can happen if we activate the action set after the launch.
+                                               refresh(fContextService.getActiveContext());
+                                       }
+                               }
+                       });
+               }
+       }
 
     @Override
     public void dispose() {