Bug 141027 - debugger does not switch jsp editor when debugging jsp
Summary: debugger does not switch jsp editor when debugging jsp
Status: CLOSED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Debug (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: 3.2 RC4   Edit
Assignee: Kevin Barnes CLA
QA Contact:
URL:
Whiteboard:
Keywords: greatbug
Depends on:
Blocks:
 
Reported: 2006-05-10 10:03 EDT by Kaloyan Raev CLA
Modified: 2008-05-28 10:58 EDT (History)
5 users (show)

See Also:


Attachments
zipped demo project (3.38 KB, application/octet-stream)
2006-05-10 10:04 EDT, Kaloyan Raev CLA
no flags Details
screenshot (29.49 KB, image/png)
2006-05-10 10:05 EDT, Kaloyan Raev CLA
no flags Details
Patch (1.33 KB, patch)
2006-05-10 10:05 EDT, Kaloyan Raev CLA
no flags Details | Diff
updated patch (3.05 KB, patch)
2006-05-10 14:02 EDT, Darin Wright CLA
no flags Details | Diff
updated patch (3.24 KB, patch)
2006-05-10 14:27 EDT, Darin Wright CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kaloyan Raev CLA 2006-05-10 10:03:39 EDT
Problem: 
When debugging JSP file that includes another JSP file, the debugger does not switch the JSP editors when the execution flow goes from the one JSP to the another. 

How to reproduce:  
1. Make a web project (zip attached) with two JSPs: foo.jsp and bar.jsp. foo.jsp includes bar.jsp. 
2. Put breakpoint on the following places: 
  2.1. foo.jsp, line 4
  2.2. bar.jsp, line 4
3. request foo.jsp, ex. http://<host>:<port>/debug/foo.jsp
4. the execution stops on the breakpoint at foo.jsp, line 4. The stack trace in the Debug view and the debugger pointer in the JSP editor show the correct data. 
5. press F8 (resume) to advance to the next breakpoint. 
6. the execution stops on the breakpoint at bar.jsp, line 4. The stack trace in the Debug view correctly shows bar.jsp:4, but the JSP editor still shows foo.jsp and the debugger pointer is at line 4, but in foo.jsp instead of bar.jsp (see attached screenshot). 

Analysis: 
When suspending the execution flow, the stack frames in the Debug view are recomputed. This invokes the JDIStackFrame.bind() method for the stack frame representing the top of the stack - where our breakpoint is. When the execution goes from code in foo.jsp to code in bar.jsp, it is attempted the same stack frame to be updated with the new source code location. The check in on line 151 in JDIStackFrame allows this: 

  if (location.method().equals(fLocation.method())) {
    ...
  }
    
This is because the fMethod in the new and old location is one and the same: "_jspService". The result is that the same stack frame object is reused for the new source file. And when StackFrameSourceDisplayAdapter.displaySource():152 is called it is seen that the stack frame object is the old one and re-lookup of the source locator is not scheduled, which results in not switching the JSP editor. 

Solution: 
One possible solution is to extend the check mentioned above in JDIStackFrame.bind():151 like this: 

  if (location.sourceName().equals(fLocation.sourceName()) && 
      location.method().equals(fLocation.method())) {
    ...
  }

Note that in addition to the method comparision, it is the sourceName compared, too. In our case the sourceName of the old location is "foo.jsp" and for the new one - "bar.jsp". This forces new stack frame object for the new location which later forces the source locator to be re-looked up. 

Patch with the described solution is attached.
Comment 1 Kaloyan Raev CLA 2006-05-10 10:04:50 EDT
Created attachment 40937 [details]
zipped demo project
Comment 2 Kaloyan Raev CLA 2006-05-10 10:05:20 EDT
Created attachment 40939 [details]
screenshot
Comment 3 Kaloyan Raev CLA 2006-05-10 10:05:48 EDT
Created attachment 40940 [details]
Patch
Comment 4 Darin Wright CLA 2006-05-10 10:16:33 EDT
Moving to web tools.
Comment 5 Darin Wright CLA 2006-05-10 10:19:09 EDT
Moved to soon....
Comment 6 Darin Wright CLA 2006-05-10 14:02:18 EDT
Created attachment 40987 [details]
updated patch

This patch addresses the possibility of exceptions occurring when retrieving the source name debug attributes from a location.
Comment 7 Darin Wright CLA 2006-05-10 14:27:40 EDT
Created attachment 40994 [details]
updated patch

More efficient patch, avoids going over the wire to the target to get the source names unless required.
Comment 8 Darin Wright CLA 2006-05-10 14:38:17 EDT
Marking as RC4 candidate.
Comment 9 Darin Wright CLA 2006-05-10 14:44:05 EDT
Risk: This is a low risk fix important to web tooling. The bug is that for a JSR045 based debugger, when a Java method maps to more than one non-Java source file (JSP in this case), source lookup will not be performed when stepping or resuming to another breakpoint in the same method.

The fix is to test that the frame corresponds to the same method and same source file before re-using the frame. Note, for efficiency, the fix only tests source file names in the case that a non-default stratum is present in the declaring type of the method.

CC'ing Jeff and Martin for RC4 approval.
Comment 10 Darin Wright CLA 2006-05-10 14:46:45 EDT
Marking as a 'great bug'. The bug is a good find, well described, includes a test case, and also presents a solution. Although the contributed patch was not used exactly, the same approach is used in our solution. 
Comment 11 Jeff McAffer CLA 2006-05-11 09:58:38 EDT
+1
Comment 12 Martin Aeschlimann CLA 2006-05-11 10:05:58 EDT
patch looks safe (I didn't have the setup to test if it fixes the bug)
+1 for 3.2 RC4
Comment 13 Darin Wright CLA 2006-05-11 10:10:49 EDT
We've tested the patch using Tomcat and the javafamily examples JSP support.

Applied our patch.
Comment 14 Darin Wright CLA 2006-05-11 10:11:09 EDT
Fixed. Please verify, Kevin.
Comment 15 Kevin Barnes CLA 2006-05-11 11:51:44 EDT
verified
Comment 16 Kaloyan Raev CLA 2008-05-28 10:58:34 EDT
Closing