diff --git a/bundles/org.eclipse.core.commands/src/org/eclipse/core/internal/commands/util/Util.java b/bundles/org.eclipse.core.commands/src/org/eclipse/core/internal/commands/util/Util.java index 42c748b5f06..52710ca8258 100644 --- a/bundles/org.eclipse.core.commands/src/org/eclipse/core/internal/commands/util/Util.java +++ b/bundles/org.eclipse.core.commands/src/org/eclipse/core/internal/commands/util/Util.java @@ -255,14 +255,16 @@ public static final String getHelpContextId(Command command) { String contextId = null; if (method != null) { - boolean accessible = method.isAccessible(); - method.setAccessible(true); - try { - contextId = (String) method.invoke(command); - } catch (Exception e) { - // do nothing + boolean accessible = method.canAccess(command); + if (method.trySetAccessible()) { + try { + contextId = (String) method.invoke(command); + } catch (Exception ignored) { + // do nothing + } finally { + method.setAccessible(accessible); + } } - method.setAccessible(accessible); } return contextId; } diff --git a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/CTabRendering.java b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/CTabRendering.java index f562024aaff..d280e10502d 100644 --- a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/CTabRendering.java +++ b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/CTabRendering.java @@ -1254,14 +1254,15 @@ public ReflectionSupport(T instance) { protected Object getFieldValue(Field field) { Object value = null; if (field != null) { - boolean accessible = field.isAccessible(); - try { - field.setAccessible(true); - value = field.get(instance); - } catch (Exception exc) { - // do nothing - } finally { - field.setAccessible(accessible); + boolean accessible = field.canAccess(instance); + if (field.trySetAccessible()) { + try { + value = field.get(instance); + } catch (Exception ignored) { + // do nothing + } finally { + field.setAccessible(accessible); + } } } return value;