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

Bug 276966

Summary: Stepping over a line of code that throws NPE causes the debugger to lose it's way
Product: [Eclipse Project] JDT Reporter: Bryan Hunt <bhunt>
Component: DebugAssignee: JDT-Debug-Inbox <jdt-debug-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: darin.eclipse
Version: 3.5   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS X   
Whiteboard: stalebug
Attachments:
Description Flags
movie showing the problem none

Description Bryan Hunt CLA 2009-05-19 13:56:11 EDT
Build I20090518-2000

If you step over a line of code that throws an NPE, the debugger will not take you to the catch.  Instead, the thread says (Stepping) forever and the program continues under it's own control.
Comment 1 Darin Wright CLA 2009-05-19 14:27:58 EDT
Appears to be a regression since 3.4
Comment 2 Darin Wright CLA 2009-05-19 16:22:08 EDT
Actually, there is no regression here - behavior depends on how the "Java > Debug > Suspend execution on uncaught exception" preference is set (and is the same in 3.4). When *on*, execution suspends when stepping. When *off* execution resumes when stepping over the NPE.

There is a bug here however. The user is stepping, so execution should not resume out from under them.
Comment 3 Bryan Hunt CLA 2009-05-19 16:27:31 EDT
FYI, Suspend execution on uncaught exceptions is checked in my dev env.
Comment 4 Darin Wright CLA 2009-05-19 16:47:11 EDT
It also seems to be VM sensitive. For example, using Sun Java 6, stepping over an NPE with the option to suspend on exceptions *off*, I end up in the method "java.lang.Thread.dispatchUncaughtException(Throwable) line: 1821". Using Java 5, execution is resumed. On Java 6, a step end event is sent via JDWP, but on Java 5, the event is not present - instead there is a thread death event.

If the step event is not produced by the VM, there is nothing we can do about this. Will test on Mac, to see what happens (this is Win XP).

Java 6 trace (where step over does complete)

JDI Event Set: {VMStartEvent: 0}
JDI Event Set: {ThreadStartEvent: 3}
JDI Event Set: {ClassPrepareEvent: 9}
JDI Event Set: {BreakpointEvent: 20}
JDI Event Set: {StepEvent: 21}
JDI Event Set: {StepEvent: 22}


Java 5 trace (where step over does not complete)

JDI Event Set: {VMStartEvent: 0}
JDI Event Set: {ThreadStartEvent: 3}
JDI Event Set: {ThreadStartEvent: 3}
JDI Event Set: {ClassPrepareEvent: 9}
JDI Event Set: {BreakpointEvent: 20}
JDI Event Set: {StepEvent: 21}
JDI Event Set: {ThreadDeathEvent: 4}
Comment 5 Darin Wright CLA 2009-05-19 17:20:21 EDT
This also works for me on Mac. When the preference to suspend on uncaught exceptions is on, stepping stops when the exception is hit, with the following event trace:

JDI Event Set: {VMStartEvent: 0}
JDI Event Set: {ThreadStartEvent: 3}
JDI Event Set: {ThreadStartEvent: 3}
JDI Event Set: {ClassPrepareEvent: 5}
JDI Event Set: {BreakpointEvent: 13}
JDI Event Set: {StepEvent: 14}
JDI Event Set: {ExceptionEvent: 12}

When the preference is off, stepping resumes as there is no step end event - just a thread death event.

JDI Event Set: {VMStartEvent: 0}
JDI Event Set: {ThreadStartEvent: 3}
JDI Event Set: {ThreadStartEvent: 3}
JDI Event Set: {ClassPrepareEvent: 5}
JDI Event Set: {BreakpointEvent: 10}
JDI Event Set: {StepEvent: 11}
JDI Event Set: {ThreadDeathEvent: 4}
Comment 6 Bryan Hunt CLA 2009-05-19 17:31:02 EDT
So that means you can't repo the problem?
Comment 7 Bryan Hunt CLA 2009-05-19 18:03:57 EDT
Created attachment 136402 [details]
movie showing the problem
Comment 8 Darin Wright CLA 2009-05-20 14:16:29 EDT
I cannot reproduce. Does it happen with a simple program like this:


public class StepOverNPE implements Runnable {
	public static void main(String[] args) {
		StepOverNPE overNPE = new StepOverNPE();
		Thread thread = new Thread(overNPE);
		thread.start();
		System.out.println("yay"); // BREAKPOINT
	}

	/* (non-Javadoc)
	 * @see java.lang.Runnable#run()
	 */
	public void run() {
		Iterator<String> it = null; // BREAKPOINT & STEP
		while (it.hasNext()) {
			String string = (String) it.next();
			System.out.println(string);
		}
	}
	
}
Comment 9 Bryan Hunt CLA 2009-05-20 15:55:49 EDT
I cannot reproduce the problem with your simple test program.  I even tried wrapping the code in a plugin and it properly suspends on the NPE
Comment 10 Eclipse Genie CLA 2020-01-28 16:46:23 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. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. 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.