Skip to content

Commit 30d226b

Browse files
gvdutragabrieldutra
andauthored
Avoid updating disposed menu items (#7738)
Co-authored-by: gabrieldutra <gdutra3@gatech.edu>
1 parent 198bccd commit 30d226b

2 files changed

Lines changed: 49 additions & 1 deletion

File tree

ui/src/main/java/org/apache/hop/ui/core/gui/GuiMenuWidgets.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ public MenuItem enableMenuItem(
365365
boolean hasCapability =
366366
handler != null ? handler.hasCapability(permission) : fileType.hasCapability(permission);
367367
boolean enable = hasCapability && active;
368-
if (menuItem != null && enable != menuItem.isEnabled()) {
368+
if (menuItem != null && !menuItem.isDisposed() && enable != menuItem.isEnabled()) {
369369
menuItem.setEnabled(enable);
370370
}
371371
menuEnabledMap.put(id, enable);
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to you under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.hop.ui.core.gui;
18+
19+
import static org.mockito.Mockito.mock;
20+
import static org.mockito.Mockito.never;
21+
import static org.mockito.Mockito.verify;
22+
import static org.mockito.Mockito.when;
23+
24+
import java.util.Map;
25+
import org.apache.hop.ui.hopgui.file.IHopFileType;
26+
import org.eclipse.swt.widgets.MenuItem;
27+
import org.junit.jupiter.api.Test;
28+
29+
class GuiMenuWidgetsDisposedTest {
30+
31+
@Test
32+
void ignoresDisposedMenuItemWhenUpdatingCapability() {
33+
String id = "file-save";
34+
String permission = "save";
35+
IHopFileType fileType = mock(IHopFileType.class);
36+
MenuItem menuItem = mock(MenuItem.class);
37+
when(fileType.hasCapability(permission)).thenReturn(true);
38+
when(menuItem.isDisposed()).thenReturn(true);
39+
40+
GuiMenuWidgets widgets = new GuiMenuWidgets();
41+
widgets.setMenuItemMap(Map.of(id, menuItem));
42+
43+
widgets.enableMenuItem(fileType, id, permission);
44+
45+
verify(menuItem, never()).isEnabled();
46+
verify(menuItem, never()).setEnabled(true);
47+
}
48+
}

0 commit comments

Comments
 (0)