Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 376213

Summary: [win32] MenuItem.setEnabled: "Cannot set the enabled state"
Product: [Eclipse Project] Platform Reporter: Thomas Singer <eclipse>
Component: SWTAssignee: Platform-SWT-Inbox <platform-swt-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: carolynmacleod4, flavio.donze, niraj.modi, paolo.bazzi, Silenio_Quarti
Version: 4.4Keywords: triaged
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
See Also: https://bugs.eclipse.org/bugs/show_bug.cgi?id=440866
Whiteboard: stalebug

Description Thomas Singer CLA 2012-04-05 14:36:02 EDT
Build Identifier: 3.8M2

A user of our application reported this exception without further details:

org.eclipse.swt.SWTError: Cannot set the enabled state
	at org.eclipse.swt.SWT.error(SWT.java:4309)
	at org.eclipse.swt.SWT.error(SWT.java:4198)
	at org.eclipse.swt.SWT.error(SWT.java:4169)
	at org.eclipse.swt.widgets.Widget.error(Widget.java:468)
	at org.eclipse.swt.widgets.MenuItem.setEnabled(MenuItem.java:717)

Windows 7 64-bit, Java 1.7.0_03

Reproducible: Couldn't Reproduce
Comment 1 Carolyn MacLeod CLA 2012-04-12 11:51:02 EDT
Hmmm... would be helpful to have a repeatable case, or at least more of the stack trace.

Was there any error immediately prior to this? Such as, perhaps, something about a widget being disposed?
Was the user able to continue working, or did they have to close eclipse?
Did this happen when they were dropping down or popping up a menu, selecting a menu item, or closing a shell?

I wonder if this is ultimately the same problem as bug 376150 and bug 321554.

Are you doing anything non-standard in your application's menu code?
Are you using straight SWT code, or Eclipse UI/JFace code?
Comment 2 Carolyn MacLeod CLA 2012-04-12 12:32:30 EDT
I decided to add similar code to bug 376150 comment 4, which calls the win32 GetLastError and prints that as the error message at the top of the stack trace. I added this code everywhere in MenuItem where the result from SetMenuItemInfo is checked.

This is now committed to master for eclipse 3.8 and 4.2:
http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=03e9337cff914952fb1035dfe434f96ff4fbfbb4

If/when your customer begins running on these platforms, and if/when the bug happens again, perhaps we will have a bit more useful info to go on.

SSQ, note that there are 2 places in MenuItem where the result from SetMenuItemInfo is not looked at: setImage and setOrientation.
Should the result be checked there also?
Comment 3 Thomas Singer CLA 2012-04-12 13:36:43 EDT
Just curious, what would be the next milestone build which will contain this change?
Comment 4 Carolyn MacLeod CLA 2012-04-12 15:58:26 EDT
Milestone M7, which is supposed to be available after May 4th (2012).
Comment 5 Thomas Singer CLA 2012-07-18 02:45:13 EDT
A customer now got following exception with SWT/JFace 3.8RC1, Java 1.7.0_03 32-bit on Windows 7 64-bit:

org.eclipse.swt.SWTError: Cannot set the enabled state [GetLastError=0x0]
	at org.eclipse.swt.SWT.error(SWT.java:4387)
	at org.eclipse.swt.widgets.MenuItem.setEnabled(MenuItem.java:719)

The shell had a Cyrillic title.
Comment 6 Carolyn MacLeod CLA 2012-07-18 10:13:46 EDT
Rats. GetLastError=0x0 does not provide any extra information.
Are you able to answer any of the questions in comment 1?
Comment 7 Thomas Singer CLA 2012-07-18 12:29:59 EDT
> Was there any error immediately prior to this? Such as, perhaps, something
> about a widget being disposed?

No, this was the first error in our application log.

> Was the user able to continue working, or did they have to close eclipse?

The user was not using Eclipse but our application which uses SWT/JFace. According to the Logs, the same exception happened later again, but with a different error:

org.eclipse.swt.SWTError: Cannot set the enabled state [GetLastError=0x57]
	at org.eclipse.swt.SWT.error(SWT.java:4387)
	at org.eclipse.swt.widgets.MenuItem.setEnabled(MenuItem.java:719)


> Did this happen when they were dropping down or popping up a menu, selecting a
> menu item, or closing a shell?

No, it happened from our code (some kind of action framework) which changes the enabled state of menu items depending on the selection.
Comment 8 Thomas Singer CLA 2013-03-22 04:18:15 EDT
This error happened again for another user. Here is the full stacktrace (maybe parts of it are of interest for you):

org.eclipse.swt.SWTError: Cannot set the enabled state [GetLastError=0x0]
	at org.eclipse.swt.SWT.error(SWT.java:4399)
	at org.eclipse.swt.widgets.MenuItem.setEnabled(MenuItem.java:719)
	at smartgit.Gk.a(SourceFile:84)
	at smartgit.FX.b(SourceFile:362)
	at smartgit.FX.c(SourceFile:262)
	at smartgit.Gi.a(SourceFile:41)
	at smartgit.Gb.a(SourceFile:51)
	at smartgit.aEo.a(SourceFile:188)
	at smartgit.aEp.a(SourceFile:66)
	at smartgit.Ep.a(SourceFile:126)
	at smartgit.Ep.a(SourceFile:16)
	at smartgit.Es.focusGained(SourceFile:103)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:139)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1077)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1058)
	at org.eclipse.swt.widgets.Control.sendFocusEvent(Control.java:2822)
	at org.eclipse.swt.widgets.Widget.wmSetFocus(Widget.java:2417)
	at org.eclipse.swt.widgets.Control.WM_SETFOCUS(Control.java:5152)
	at org.eclipse.swt.widgets.Tree.WM_SETFOCUS(Tree.java:7079)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:4598)
	at org.eclipse.swt.widgets.Tree.windowProc(Tree.java:5973)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:4976)
	at org.eclipse.swt.internal.win32.OS.CallWindowProcW(Native Method)
	at org.eclipse.swt.internal.win32.OS.CallWindowProc(OS.java:2440)
	at org.eclipse.swt.widgets.Tree.callWindowProc(Tree.java:1534)
	at org.eclipse.swt.widgets.Tree.WM_LBUTTONDOWN(Tree.java:6650)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:4564)
	at org.eclipse.swt.widgets.Tree.windowProc(Tree.java:5973)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:4976)
	at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
	at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2546)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3756)
	at smartgit.Fg.e(SourceFile:208)
	at smartgit.anc.a(SourceFile:235)
	at smartgit.anc.a(SourceFile:163)
	at smartgit.Yu.b(SourceFile:62)
	at SmartGit.main(SourceFile:11)

java.runtime.version                : "1.7.0_13-b20"
java.vm.version                     : "23.7-b01"
os.arch                             : "x86"
os.name                             : "Windows 7"

If you need more information from the log file, please let me know (our internal ticket no: 12937).
Comment 9 Thomas Singer CLA 2014-07-31 06:09:05 EDT
We've got a related exception using SWT 4.4.0 on Windows 7 32-bit:

org.eclipse.swt.SWTError: Cannot get the enabled state
	at org.eclipse.swt.SWT.error(SWT.java:4423)
	at org.eclipse.swt.SWT.error(SWT.java:4312)
	at org.eclipse.swt.SWT.error(SWT.java:4283)
	at org.eclipse.swt.widgets.Widget.error(Widget.java:472)
	at org.eclipse.swt.widgets.MenuItem.getEnabled(MenuItem.java:418)
	at org.eclipse.swt.widgets.MenuItem.fillAccel(MenuItem.java:249)
	at org.eclipse.swt.widgets.Decorations.createAccelerators(Decorations.java:395)
	at org.eclipse.swt.widgets.Decorations.translateMenuAccelerator(Decorations.java:1488)
	at org.eclipse.swt.widgets.Shell.translateAccelerator(Shell.java:1951)
	at org.eclipse.swt.widgets.Control.translateAccelerator(Control.java:3942)
	at org.eclipse.swt.widgets.Display.translateAccelerator(Display.java:4761)
	at org.eclipse.swt.widgets.Display.filterMessage(Display.java:1276)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3755)
	at com.syntevo.q.gui.QSwt.dispatchEvents(SourceFile:251)

Most likely it was a consequential error of bug 440866.
Comment 10 Flavio Donze CLA 2016-04-05 08:36:10 EDT
Found this error in log file of a client, maybe this stacktrace helps:

[2016-01-14 16:37:35,241] ERROR: com.softmodeler.osgi.over.slf4j.ext.org.eclipse.equinox.logger - Unhandled event loop exception
org.eclipse.swt.SWTError: Cannot set the enabled state [GetLastError=0x57]
	at org.eclipse.swt.SWT.error(SWT.java:4517) ~[na:na]
	at org.eclipse.swt.widgets.MenuItem.setEnabled(MenuItem.java:744) ~[na:na]
	at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.updateMenuItem(HandledContributionItem.java:466) ~[na:na]
	at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.update(HandledContributionItem.java:425) ~[na:na]
	at org.eclipse.jface.action.MenuManager.update(MenuManager.java:861) ~[na:na]
	at org.eclipse.jface.action.MenuManager.update(MenuManager.java:861) ~[na:na]
	at org.eclipse.ui.internal.Workbench.updateActiveWorkbenchWindowMenuManager(Workbench.java:3373) ~[na:na]
	at org.eclipse.ui.internal.Workbench.access$0(Workbench.java:3359) ~[na:na]
	at org.eclipse.ui.internal.Workbench$1.bindingManagerChanged(Workbench.java:3354) ~[na:na]
	at org.eclipse.jface.bindings.BindingManager.fireBindingManagerChanged(BindingManager.java:901) ~[na:na]
	at org.eclipse.jface.bindings.BindingManager.setActiveBindings(BindingManager.java:2178) ~[na:na]
	at org.eclipse.jface.bindings.BindingManager.recomputeBindings(BindingManager.java:1743) ~[na:na]
	at org.eclipse.jface.bindings.BindingManager.contextManagerChanged(BindingManager.java:690) ~[na:na]
	at org.eclipse.core.commands.contexts.ContextManager.fireContextManagerChanged(ContextManager.java:162) ~[na:na]
	at org.eclipse.core.commands.contexts.ContextManager.removeActiveContext(ContextManager.java:243) ~[na:na]
	at org.eclipse.ui.internal.contexts.ContextAuthority.updateContext(ContextAuthority.java:761) ~[na:na]
	at org.eclipse.ui.internal.contexts.ContextAuthority.activateContext(ContextAuthority.java:173) ~[na:na]
	at org.eclipse.ui.internal.contexts.ContextAuthority.checkWindowType(ContextAuthority.java:245) ~[na:na]
	at org.eclipse.ui.internal.contexts.ContextAuthority.updateEvaluationContext(ContextAuthority.java:795) ~[na:na]
	at org.eclipse.ui.internal.services.ExpressionAuthority.sourceChanged(ExpressionAuthority.java:289) ~[na:na]
	at org.eclipse.ui.AbstractSourceProvider.fireSourceChanged(AbstractSourceProvider.java:90) ~[na:na]
	at org.eclipse.ui.internal.services.WorkbenchSourceProvider.access$10(WorkbenchSourceProvider.java:1) ~[na:na]
	at org.eclipse.ui.internal.services.WorkbenchSourceProvider$6.handleEvent(WorkbenchSourceProvider.java:800) ~[na:na]
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84) ~[na:na]
	at org.eclipse.swt.widgets.Display.filterEvent(Display.java:1266) ~[na:na]
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1112) ~[na:na]
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1137) ~[na:na]
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1122) ~[na:na]
	at org.eclipse.swt.widgets.Decorations.WM_ACTIVATE(Decorations.java:1673) ~[na:na]
	at org.eclipse.swt.widgets.Shell.WM_ACTIVATE(Shell.java:2193) ~[na:na]
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:4659) ~[na:na]
	at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:339) ~[na:na]
	at org.eclipse.swt.widgets.Decorations.windowProc(Decorations.java:1633) ~[na:na]
	at org.eclipse.swt.widgets.Shell.windowProc(Shell.java:2117) ~[na:na]
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:5050) ~[na:na]
	at org.eclipse.swt.internal.win32.OS.BringWindowToTop(Native Method) ~[na:na]
	at org.eclipse.swt.widgets.Decorations.bringToTop(Decorations.java:230) ~[na:na]
	at org.eclipse.swt.widgets.Shell.open(Shell.java:1244) ~[na:na]
	at org.eclipse.jface.window.Window.open(Window.java:799) ~[na:na]
	at org.eclipse.jface.dialogs.MessageDialog.open(MessageDialog.java:330) ~[na:na]
	at org.eclipse.jface.dialogs.MessageDialog.open(MessageDialog.java:360) ~[na:na]
	at org.eclipse.jface.dialogs.MessageDialog.openWarning(MessageDialog.java:469) ~[na:na]
	at com.softmodeler.ui.handler.CommitHandler.execute(CommitHandler.java:99) ~[na:na]
	at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:295) ~[na:na]
	at org.eclipse.ui.internal.handlers.E4HandlerProxy.execute(E4HandlerProxy.java:90) ~[na:na]
	at sun.reflect.GeneratedMethodAccessor87.invoke(Unknown Source) ~[na:na]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_60]
	at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_60]
	at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56) ~[na:na]
	at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:252) ~[na:na]
	at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:234) ~[na:na]
	at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:132) ~[na:na]
	at org.eclipse.e4.core.commands.internal.HandlerServiceHandler.execute(HandlerServiceHandler.java:152) ~[na:na]
	at org.eclipse.core.commands.Command.executeWithChecks(Command.java:493) ~[na:na]
	at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:486) ~[na:na]
	at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:210) ~[na:na]
	at org.eclipse.ui.internal.handlers.LegacyHandlerService.executeCommand(LegacyHandlerService.java:343) ~[na:na]
	at org.eclipse.ui.menus.CommandContributionItem.handleWidgetSelection(CommandContributionItem.java:830) ~[na:na]
	at org.eclipse.ui.menus.CommandContributionItem.access$21(CommandContributionItem.java:816) ~[na:na]
	at org.eclipse.ui.menus.CommandContributionItem$5.handleEvent(CommandContributionItem.java:806) ~[na:na]
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84) ~[na:na]
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4362) ~[na:na]
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1113) ~[na:na]
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4180) ~[na:na]
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3769) ~[na:na]
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1127) ~[na:na]
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337) ~[na:na]
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1018) ~[na:na]
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:156) ~[na:na]
	at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:654) ~[na:na]
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337) ~[na:na]
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:598) ~[na:na]
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150) ~[na:na]
	at com.softmodeler.ui.rcp.RCPApplication.start(RCPApplication.java:142) ~[na:na]
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196) ~[na:na]
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134) ~[na:na]
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104) ~[na:na]
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380) ~[na:na]
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235) ~[na:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_60]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_60]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_60]
	at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_60]
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:669) ~[org.eclipse.equinox.launcher_1.3.100.v20150511-1540.jar:na]
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:608) ~[org.eclipse.equinox.launcher_1.3.100.v20150511-1540.jar:na]
	at org.eclipse.equinox.launcher.Main.run(Main.java:1515) ~[org.eclipse.equinox.launcher_1.3.100.v20150511-1540.jar:na]
Comment 11 Niraj Modi CLA 2017-07-04 10:52:23 EDT
I was going through the meaning of error codes on MSDN:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx

(In reply to Thomas Singer from comment #8)
> This error happened again for another user. Here is the full stacktrace
> (maybe parts of it are of interest for you):
> 
> org.eclipse.swt.SWTError: Cannot set the enabled state [GetLastError=0x0]
>	at org.eclipse.swt.SWT.error(SWT.java:4399)
Here GetMenuItemInfo function fails but GetLastError() returns '0x0'(ERROR_SUCCESS) which stands for successful function call.
So, it looks like some bug at native level is causing this confusion.
Am not sure, what the correct behavior here either to throw error or to continue. Will investigate on this.
Comment 12 Niraj Modi CLA 2017-07-04 10:52:51 EDT
(In reply to Flavio Donze from comment #10)
> Found this error in log file of a client, maybe this stacktrace helps:
> 
> [2016-01-14 16:37:35,241] ERROR:
> com.softmodeler.osgi.over.slf4j.ext.org.eclipse.equinox.logger - Unhandled
> event loop exception
> org.eclipse.swt.SWTError: Cannot set the enabled state [GetLastError=0x57]
>	at org.eclipse.swt.SWT.error(SWT.java:4517) ~[na:na]
BTW, '0x57' stands for ERROR_INVALID_PARAMETER -- The parameter is incorrect.
This looks like a valid error flow.
Comment 13 Thomas Singer CLA 2017-09-17 12:47:45 EDT
The latest stacktrace I've got for SWT 4.723 on Windows 10/64-bit:

org.eclipse.swt.SWTError: Cannot get the enabled state
	at org.eclipse.swt.SWT.error(SWT.java:4559)
	at org.eclipse.swt.SWT.error(SWT.java:4448)
	at org.eclipse.swt.SWT.error(SWT.java:4419)
	at org.eclipse.swt.widgets.Widget.error(Widget.java:482)
	at org.eclipse.swt.widgets.MenuItem.getEnabled(MenuItem.java:424)
	at org.eclipse.swt.widgets.MenuItem.isEnabled(MenuItem.java:551)
	at org.eclipse.swt.widgets.Control.WM_COMMAND(Control.java:4962)
	at org.eclipse.swt.widgets.Shell.WM_COMMAND(Shell.java:2325)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:4825)
	at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:359)
	at org.eclipse.swt.widgets.Decorations.windowProc(Decorations.java:1656)
	at org.eclipse.swt.widgets.Shell.windowProc(Shell.java:2199)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:5194)
	at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
	at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2553)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3818)
Comment 14 Eclipse Genie CLA 2019-11-28 14:43:13 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.