Skip to content

Commit 8942682

Browse files
Fixed the java breakpoints no line attribute error dialog regarding the
"Don't tell me again" checkbox. The value wasn't stored in the preference store due to a bug in ErrorDialogWithToggle. Added also a testcase to easily reproduce the dialog opening and checking its functionality fixes ticket https://github.com/eclipse-jdt/eclipse.jdt.ui/issues/2648
1 parent 77be489 commit 8942682

File tree

4 files changed

+137
-2
lines changed

4 files changed

+137
-2
lines changed

org.eclipse.jdt.debug.tests/META-INF/MANIFEST.MF

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ Require-Bundle: org.eclipse.ui.ide;resolution:=optional,
4949
org.eclipse.test.performance,
5050
org.eclipse.ltk.core.refactoring,
5151
org.eclipse.jdt.core.manipulation,
52-
org.eclipse.core.filesystem
52+
org.eclipse.core.filesystem,
53+
org.mockito.mockito-core;bundle-version="5.20.0"
5354
Bundle-ActivationPolicy: lazy
5455
Bundle-RequiredExecutionEnvironment: JavaSE-21
5556
Eclipse-BundleShape: dir

org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/AutomatedSuite.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@
150150
import org.eclipse.jdt.debug.tests.ui.DebugViewTests;
151151
import org.eclipse.jdt.debug.tests.ui.DetailPaneManagerTests;
152152
import org.eclipse.jdt.debug.tests.ui.JavaSnippetEditorTest;
153+
import org.eclipse.jdt.debug.tests.ui.NoLineNumberAttributesStatusHandlerTest;
153154
import org.eclipse.jdt.debug.tests.ui.OpenFromClipboardTests;
154155
import org.eclipse.jdt.debug.tests.ui.ViewManagementTests;
155156
import org.eclipse.jdt.debug.tests.ui.VirtualThreadsDebugViewTests;
@@ -341,6 +342,9 @@ public AutomatedSuite() {
341342
// Scrapbook editor tests
342343
addTest(new TestSuite(JavaSnippetEditorTest.class));
343344

345+
// No Line Number Attributes Status Handler tests
346+
addTest(new TestSuite(NoLineNumberAttributesStatusHandlerTest.class));
347+
344348
// Debug hover tests
345349
addTest(new TestSuite(DebugHoverTests.class));
346350

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
package org.eclipse.jdt.debug.tests.ui;
2+
3+
import static org.mockito.Mockito.mock;
4+
import static org.mockito.Mockito.when;
5+
6+
import java.lang.reflect.InvocationTargetException;
7+
import java.lang.reflect.Method;
8+
import java.util.ArrayList;
9+
import java.util.Collections;
10+
import java.util.List;
11+
12+
import org.eclipse.core.runtime.CoreException;
13+
import org.eclipse.core.runtime.ILogListener;
14+
import org.eclipse.core.runtime.IStatus;
15+
import org.eclipse.core.runtime.Platform;
16+
import org.eclipse.core.runtime.Status;
17+
import org.eclipse.debug.core.DebugPlugin;
18+
import org.eclipse.jdi.internal.ClassTypeImpl;
19+
import org.eclipse.jdi.internal.ReferenceTypeImpl;
20+
import org.eclipse.jdt.internal.debug.ui.DebugUIMessages;
21+
import org.eclipse.jdt.internal.debug.ui.ErrorDialogWithToggle;
22+
import org.eclipse.jdt.internal.debug.ui.IJDIPreferencesConstants;
23+
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
24+
import org.eclipse.jdt.internal.debug.ui.NoLineNumberAttributesStatusHandler;
25+
import org.eclipse.jface.dialogs.IDialogConstants;
26+
import org.eclipse.jface.preference.IPreferenceStore;
27+
import org.eclipse.osgi.util.NLS;
28+
import org.eclipse.swt.widgets.Button;
29+
import org.eclipse.test.OrderedTestSuite;
30+
import org.eclipse.ui.PlatformUI;
31+
import org.junit.Test;
32+
33+
/**
34+
* This test is checking the {@link NoLineNumberAttributesStatusHandler} the functionality that the ok button click is saving the state in the
35+
* preference store.
36+
*/
37+
public class NoLineNumberAttributesStatusHandlerTest extends AbstractDebugUiTests {
38+
39+
public static junit.framework.Test suite() {
40+
return new OrderedTestSuite(NoLineNumberAttributesStatusHandlerTest.class);
41+
}
42+
43+
private final class ListLogListener implements ILogListener {
44+
private final List<IStatus> loggedEntries;
45+
46+
private ListLogListener(List<IStatus> loggedEntries) {
47+
this.loggedEntries = loggedEntries;
48+
}
49+
50+
@Override
51+
public void logging(IStatus status, String plugin) {
52+
if (status.isMultiStatus() && status.getChildren().length == 1) {
53+
loggedEntries.add(status.getChildren()[0]);
54+
}
55+
}
56+
}
57+
58+
public NoLineNumberAttributesStatusHandlerTest(String name) {
59+
super(name);
60+
}
61+
62+
@Test
63+
public void testPreferenceSettings() throws CoreException, NoSuchMethodException, SecurityException, IllegalAccessException, InvocationTargetException {
64+
List<IStatus> loggedEntries = new ArrayList<>();
65+
ILogListener listener = new ListLogListener(loggedEntries);
66+
67+
Platform.addLogListener(listener);
68+
try {
69+
IPreferenceStore preferenceStore = JDIDebugUIPlugin.getDefault().getPreferenceStore();
70+
71+
IStatus status = new Status(IStatus.ERROR, "org.eclipse.jdt.debug", 162, "Teststatus", null);
72+
73+
simulateErrorDialogWithToggleExecution(preferenceStore, status, true);
74+
assertFalse(preferenceStore.getBoolean(IJDIPreferencesConstants.PREF_ALERT_UNABLE_TO_INSTALL_BREAKPOINT));
75+
assertTrue(loggedEntries.isEmpty());
76+
triggerNoLineAttributesStatusHandler(status);
77+
assertEquals(0, Collections.frequency(loggedEntries, status));
78+
79+
simulateErrorDialogWithToggleExecution(preferenceStore, status, false);
80+
assertTrue(preferenceStore.getBoolean(IJDIPreferencesConstants.PREF_ALERT_UNABLE_TO_INSTALL_BREAKPOINT));
81+
assertTrue(loggedEntries.isEmpty());
82+
triggerNoLineAttributesStatusHandler(status);
83+
assertEquals(1, Collections.frequency(loggedEntries, status));
84+
loggedEntries.clear();
85+
86+
simulateErrorDialogWithToggleExecution(preferenceStore, status, true);
87+
assertFalse(preferenceStore.getBoolean(IJDIPreferencesConstants.PREF_ALERT_UNABLE_TO_INSTALL_BREAKPOINT));
88+
89+
assertTrue(loggedEntries.isEmpty());
90+
triggerNoLineAttributesStatusHandler(status);
91+
assertEquals(0, Collections.frequency(loggedEntries, status));
92+
} finally {
93+
Platform.removeLogListener(listener);
94+
}
95+
96+
}
97+
98+
private void triggerNoLineAttributesStatusHandler(IStatus status) throws CoreException {
99+
ReferenceTypeImpl referenceTypeImpl = new ClassTypeImpl(null, null);
100+
referenceTypeImpl.setName("TestRefTypeName");
101+
DebugPlugin.getDefault().getStatusHandler(status).handleStatus(status, referenceTypeImpl);
102+
}
103+
104+
private void simulateErrorDialogWithToggleExecution(IPreferenceStore preferenceStore, IStatus status, boolean value) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
105+
ErrorDialogWithToggle dialog;
106+
Method method;
107+
dialog = new ErrorDialogWithToggle(PlatformUI.getWorkbench().getModalDialogShellProvider().getShell(), DebugUIMessages.NoLineNumberAttributesStatusHandler_Java_Breakpoint_1, NLS.bind(DebugUIMessages.NoLineNumberAttributesStatusHandler_2, "HelloWorld"), status, IJDIPreferencesConstants.PREF_ALERT_UNABLE_TO_INSTALL_BREAKPOINT, DebugUIMessages.NoLineNumberAttributesStatusHandler_3, preferenceStore) {
108+
@Override
109+
protected org.eclipse.swt.widgets.Button getToggleButton() {
110+
Button mockedButton = mock(Button.class);
111+
when(mockedButton.getSelection()).thenReturn(value);
112+
return mockedButton;
113+
}
114+
};
115+
method = ErrorDialogWithToggle.class.getDeclaredMethod("buttonPressed", Integer.TYPE);
116+
method.setAccessible(true);
117+
try {
118+
method.invoke(dialog, IDialogConstants.OK_ID);
119+
} finally {
120+
method.setAccessible(false);
121+
}
122+
}
123+
}

org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/ErrorDialogWithToggle.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,18 @@ protected void buttonPressed(int id, IDebugTarget target) {
105105
if (id == IDialogConstants.OK_ID) { // was the OK button pressed?
106106
storePreference(target);
107107
}
108+
buttonPressed(id);
109+
}
110+
111+
@Override
112+
protected void buttonPressed(int id) {
113+
if (id == IDialogConstants.OK_ID) { // was the OK button pressed?
114+
fStore.setValue(fPreferenceKey, !getToggleButton().getSelection());
115+
}
108116
super.buttonPressed(id);
109117
}
110118

111119
private void storePreference(IDebugTarget target) {
112-
fStore.setValue(fPreferenceKey, !getToggleButton().getSelection());
113120
if (fToggleButton2 != null) {
114121
if (target instanceof JDIDebugTarget jdiTarget) {
115122
jdiTarget.setHcrDebugErrorPref(fToggleButton2.getSelection());

0 commit comments

Comments
 (0)