summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorPaul Elder2013-04-17 09:24:24 (EDT)
committer Paul Webster2013-05-24 12:50:23 (EDT)
commite7ed31884ab79edf135c9540efdb3409f251adfb (patch)
treed2010d0e7c981464b964172212e3655d4514857c
parente41dbc7b42e73b036f7e54669e0197b3554ec0e2 (diff)
downloadeclipse.platform.ui-e7ed31884ab79edf135c9540efdb3409f251adfb.zip
eclipse.platform.ui-e7ed31884ab79edf135c9540efdb3409f251adfb.tar.gz
eclipse.platform.ui-e7ed31884ab79edf135c9540efdb3409f251adfb.tar.bz2
398925: After prolonged usage Eclipse becomes unusable :
java.lang.Object cannot be cast to org.eclipse.e4.core.commands.EHandlerService Added defensive code that checks for unexpected return values from IEvaluationContext.getVariable, logs a message and takes a reasonable default action. Change-Id: I6eb4e2db49f4f465ce957f87211828a150879861
-rw-r--r--bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/PartRenderingEngine.java3
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/menus/MenuHelper.java34
2 files changed, 31 insertions, 6 deletions
diff --git a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/PartRenderingEngine.java b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/PartRenderingEngine.java
index 7dc8292..76d18ec 100644
--- a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/PartRenderingEngine.java
+++ b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/PartRenderingEngine.java
@@ -876,7 +876,8 @@ public class PartRenderingEngine implements IPresentationEngine {
IEclipseContext lclContext = ctxt.getContext();
if (lclContext != null) {
IEclipseContext parentContext = lclContext.getParent();
- IEclipseContext child = parentContext.getActiveChild();
+ IEclipseContext child = parentContext != null ? parentContext
+ .getActiveChild() : null;
if (child == lclContext) {
child.deactivate();
}
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/menus/MenuHelper.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/menus/MenuHelper.java
index 22a863d..8eea2f3 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/menus/MenuHelper.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/menus/MenuHelper.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2012 IBM Corporation and others.
+ * Copyright (c) 2010, 2013 IBM Corporation 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
@@ -237,10 +237,15 @@ public class MenuHelper {
Expression visWhen = new Expression() {
@Override
public EvaluationResult evaluate(IEvaluationContext context) {
- EHandlerService service = (EHandlerService) context
- .getVariable(EHandlerService.class.getName());
- ICommandService commandService = (ICommandService) context
- .getVariable(ICommandService.class.getName());
+ EHandlerService service = getFromContext(context,
+ EHandlerService.class);
+ ICommandService commandService = getFromContext(context,
+ ICommandService.class);
+ if (service == null || commandService == null) {
+ WorkbenchPlugin
+ .log("Could not retrieve EHandlerService or ICommandService from context evaluation context."); //$NON-NLS-1$
+ return EvaluationResult.FALSE;
+ }
Command c = commandService.getCommand(commandId);
ParameterizedCommand generateCommand = ParameterizedCommand
.generateCommand(c, Collections.EMPTY_MAP);
@@ -274,6 +279,25 @@ public class MenuHelper {
return null;
}
+ /**
+ * Do a type-safe extraction of an object from the evalation context
+ *
+ * @param context
+ * the evaluation context
+ * @param expectedType
+ * the expected type
+ * @return an object of the expected type or <code>null</code>
+ * @throws NullPointerException
+ * if either argument is <code>null</code>
+ */
+ protected static <T> T getFromContext(IEvaluationContext context, Class<T> expectedType) {
+ if (context == null || expectedType == null) {
+ throw new NullPointerException();
+ }
+ final Object rawValue = context.getVariable(expectedType.getName());
+ return (expectedType.isInstance(rawValue)) ? expectedType.cast(rawValue) : null;
+ }
+
/*
* Support Utilities
*/