Bug 578899 - NPE with breakpoint in ClassLoader.getDefinedPackage()

This change adds null checks to callers of
JDIStackFrame.getUnderlyingStackFrame(), to prevent NPEs that are not
handled by JDT. Such NPEs result in an error dialog.

JDIStackFrame.getUnderlyingStackFrame() can return null, if the
JDIStackFrame object is used after JDIThread.disposeStackFrames() is
called on the respective JDIThread.

In particular, JDIStackFrame.fStackFrame is set to null on a thread
resume. When getUnderlyingStackFrame() is called with a null in
fStackFrame, and a suspended thread (e.g. the next breakpoint was hit),
the method relies on JDIThread.computeStackFrames() to set the value of
fStackFrame. This is done in JDIStackFrame.bind(). However, after a
JDIThread.disposeStackFrames() call, JDIThread no longer has a reference
to the original JDIStackFrame object, and so will not set its
fStackFrame. So getUnderlyingStackFrame() returns a null.

JDIThread.disposeStackFrames() is called when a thread start event is
sent by the debuggee JVM, and JDT finds a JDIThread object to match the
underlying JVM thread (the stack frames of that JDIThread are then
cleared).

Change-Id: I075de893c53f436c8c56e6834925c216cbf704fd
Signed-off-by: Simeon Andreev <simeon.danailov.andreev@gmail.com>
Reviewed-on: https://git.eclipse.org/r/c/jdt/eclipse.jdt.debug/+/191125
Tested-by: JDT Bot <jdt-bot@eclipse.org>
Reviewed-by: Andrey Loskutov <loskutov@gmx.de>
5 files changed