Bug 518658 - "Suspend execution on uncaught exception" not working if
"show method after a step..." is active

Change-Id: I15f4b012b0ceecd9627775e4da9101351d0299b5
Signed-off-by: Till Brychcy <register.eclipse@brychcy.de>
diff --git a/org.eclipse.jdt.debug.tests/testprograms/StepUncaught.java b/org.eclipse.jdt.debug.tests/testprograms/StepUncaught.java
new file mode 100644
index 0000000..c5191e2
--- /dev/null
+++ b/org.eclipse.jdt.debug.tests/testprograms/StepUncaught.java
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Till Brychcy 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ * 
+ * Contributors:
+ *     Till Brychcy - initial API and implementation
+ *******************************************************************************/
+
+public class StepUncaught {
+	public static void main(String[] args) {
+		try {
+			f(); // bp
+		} catch (Throwable e) {
+		}
+		g();
+	}
+
+	private static void f() {
+		throw new RuntimeException("caught");
+	}
+	private static void g() {
+		throw new RuntimeException("uncaught");
+	}
+}
diff --git a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/test/stepping/StepResultTests.java b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/test/stepping/StepResultTests.java
index 82df334..0b17dd8 100644
--- a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/test/stepping/StepResultTests.java
+++ b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/test/stepping/StepResultTests.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2016 Till Brychcy and others.
+ * Copyright (c) 2017 Till Brychcy 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
@@ -19,6 +19,9 @@
 import org.eclipse.jdt.debug.core.IJavaThread;
 import org.eclipse.jdt.debug.core.IJavaValue;
 import org.eclipse.jdt.debug.tests.AbstractDebugTest;
+import org.eclipse.jdt.internal.debug.ui.IJDIPreferencesConstants;
+import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
+import org.eclipse.jface.preference.IPreferenceStore;
 
 public class StepResultTests extends AbstractDebugTest {
 
@@ -44,7 +47,6 @@
 			assertEquals("h() returned", varInG.getName());
 			assertEquals("\"h-i\"", varInG.getValue().toString());
 
-
 			// skip the synthetic via a step filter.
 			IJavaDebugTarget javaDebugTarget = (IJavaDebugTarget) stackFrame.getDebugTarget();
 			boolean oldStepFiltersEnabled = javaDebugTarget.isStepFiltersEnabled();
@@ -470,4 +472,35 @@
 		}
 	}
 
+	public void testStepUncaught() throws Exception {
+		IPreferenceStore preferenceStore = JDIDebugUIPlugin.getDefault().getPreferenceStore();
+		boolean origPrefValue = preferenceStore.getBoolean(IJDIPreferencesConstants.PREF_SUSPEND_ON_UNCAUGHT_EXCEPTIONS);
+		preferenceStore.setValue(IJDIPreferencesConstants.PREF_SUSPEND_ON_UNCAUGHT_EXCEPTIONS, true);
+		String typeName = "StepUncaught";
+		ILineBreakpoint bp = createLineBreakpoint(15, "StepUncaught");
+		bp.setEnabled(true);
+
+		IJavaThread thread = null;
+		try {
+			thread = launchAndSuspend(typeName);
+			IJavaStackFrame stackFrame = (IJavaStackFrame) thread.getTopStackFrame();
+			assertEquals("main", stackFrame.getMethodName());
+
+			stepOver(stackFrame);
+
+			stackFrame = (IJavaStackFrame) thread.getTopStackFrame();
+			assertEquals("main", stackFrame.getMethodName());
+			assertEquals("f() threw", stackFrame.getVariables()[0].getName());
+
+			stepOverToBreakpoint(stackFrame);
+
+			stackFrame = (IJavaStackFrame) thread.getTopStackFrame();
+			assertEquals("g", stackFrame.getMethodName());
+		}
+		finally {
+			preferenceStore.setValue(IJDIPreferencesConstants.PREF_SUSPEND_ON_UNCAUGHT_EXCEPTIONS, origPrefValue);
+			terminateAndRemove(thread);
+			removeAllBreakpoints();
+		}
+	}
 }
diff --git a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/AbstractDebugTest.java b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/AbstractDebugTest.java
index b106fc4..9687b15 100644
--- a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/AbstractDebugTest.java
+++ b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/AbstractDebugTest.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2016 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 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
@@ -201,7 +201,7 @@
 			"bug329294", "bug401270", "org.eclipse.debug.tests.targets.HcrClass2", "org.eclipse.debug.tests.targets.HcrClass3", "org.eclipse.debug.tests.targets.HcrClass4",
 			"org.eclipse.debug.tests.targets.HcrClass5", "org.eclipse.debug.tests.targets.HcrClass6", "org.eclipse.debug.tests.targets.HcrClass7", "org.eclipse.debug.tests.targets.HcrClass8",
 			"org.eclipse.debug.tests.targets.HcrClass9", "TestContributedStepFilterClass", "TerminateAll_01", "TerminateAll_02", "StepResult1",
-			"StepResult2", "StepResult3", "TriggerPoint_01" };
+			"StepResult2", "StepResult3", "StepUncaught", "TriggerPoint_01" };
 
 	final String[] LAUNCH_CONFIG_NAMES_1_8 = {"LargeSourceFile"};
 
diff --git a/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDIThread.java b/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDIThread.java
index b8de172..1a0337c 100644
--- a/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDIThread.java
+++ b/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDIThread.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2016 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 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
@@ -2585,7 +2585,7 @@
 						fStepReturnTargetFrameCount = frameCount - 1; // depth of the frame that is returned to
 						addJDIEventListener(this, methodExitRequest);
 
-						ExceptionRequest exceptionRequest = manager.createExceptionRequest(null, true, true);
+						ExceptionRequest exceptionRequest = manager.createExceptionRequest(null, true, false);
 						exceptionRequest.addThreadFilter(fThread);
 						exceptionRequest.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD);
 						exceptionRequest.enable();