Bug 515206 - JavaThreadEventHandler.indexOf(IStackFrame) returns -1 during evaluation
Summary: JavaThreadEventHandler.indexOf(IStackFrame) returns -1 during evaluation
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Debug (show other bugs)
Version: 3.8.2   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 4.7 M7   Edit
Assignee: Andrey Loskutov CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-04-12 11:16 EDT by Andrey Loskutov CLA
Modified: 2018-08-14 04:46 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrey Loskutov CLA 2017-04-12 11:16:21 EDT
We've found a race condition in debug events handling in 3.8.2, but the same code is in 4.7 head.

In our code we rely on JavaThreadEventHandler.indexOf(IStackFrame) returning the proper index to select the right stack element in the Debug view on the "suspended" event. 

In some cases this method does not work properly - namely, if there is an evaluation running at same time as the "suspended" event is sent to clients. In this case, IThread.getStackFrames() returns empty array (expected and documented) and indexOf() returns -1 (not expected because not documented), the debug view can't select the right frame and the "suspend/resume" buttons shows the wrong state.

In our code we created a workaround and let indexOf() detect the running evaluation and simply wait some time, but I'm not sure if this can be accepted as a general solution.

Anyway, I plan to push a test case and a possible patch soon.
Comment 1 Eclipse Genie CLA 2017-04-28 11:16:02 EDT
New Gerrit change created: https://git.eclipse.org/r/96043
Comment 3 Sarika Sinha CLA 2017-05-22 00:58:14 EDT
http://download.eclipse.org/eclipse/downloads/drops4/I20170521-0800/testresults/html/org.eclipse.jdt.debug.tests_ep47I-unit-mac64_macosx.cocoa.x86_64_8.0.html

testComputeFrameIndexDuringEvaluation	Failure	expected:<0> but was:<-1>

junit.framework.AssertionFailedError: expected:<0> but was:<-1>
at org.eclipse.jdt.debug.tests.breakpoints.JavaThreadEventHandlerTests$1.performChecks(JavaThreadEventHandlerTests.java:157)
at org.eclipse.jdt.debug.tests.breakpoints.JavaThreadEventHandlerTests.doEvalAndRunInParallel(JavaThreadEventHandlerTests.java:211)
at org.eclipse.jdt.debug.tests.breakpoints.JavaThreadEventHandlerTests.testComputeFrameIndexDuringEvaluation(JavaThreadEventHandlerTests.java:164)
at org.eclipse.jdt.debug.tests.AbstractDebugTest.runBare(AbstractDebugTest.java:2528)
at org.eclipse.jdt.debug.tests.DebugSuite$1.run(DebugSuite.java:57)
at java.lang.Thread.run(Thread.java:745)
Comment 4 Andrey Loskutov CLA 2017-05-22 08:41:08 EDT
(In reply to Sarika Sinha from comment #3)
> http://download.eclipse.org/eclipse/downloads/drops4/I20170521-0800/
> testresults/html/org.eclipse.jdt.debug.tests_ep47I-unit-mac64_macosx.cocoa.
> x86_64_8.0.html
> 
> testComputeFrameIndexDuringEvaluation	Failure	expected:<0> but was:<-1>

I've created bug 517071.