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

Bug 342155

Summary: Monitoring an iterator in the "Watch Expressions" window affects the iterator in the actual code
Product: [Eclipse Project] JDT Reporter: Corey <coreyharden>
Component: DebugAssignee: JDT-Debug-Inbox <jdt-debug-inbox>
Status: CLOSED INVALID QA Contact:
Severity: normal    
Priority: P3 CC: daniel_megert, Michael_Rennie
Version: 3.7   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Corey CLA 2011-04-07 09:30:32 EDT
Build Identifier: 20090920-1017

Setting up a watch expression to view each iteration of an iterator in the code causes the iterator in the code to iterate.

Reproducible: Always

Steps to Reproduce:
Step 1: Consider the following code:
**********************************************
ArrayList<File> dirs = new ArrayList<File>();
dirs.add(new File("D:\\file1"));
dirs.add(new File("D:\\file2"));
dirs.add(new File("D:\\file3"));
dirs.add(new File("D:\\file4"));
dirs.add(new File("D:\\file5"));

Iterator<File> it = dirs.iterator();
while(it.hasNext()){
   File nextFile = it.next();
   System.out.println(nextFile.getName());
}
*************************************************

Step 2: Setup the following watch expression:
it.next().getName();


Step 3:
Debug the code from step 1. Notice how the watch expression evokes the next() method of the iterator which causes the iterator in the actual code to skip. This would not have an effect on production code; however, to a developer this poses a problem because it appears the code is not working correctly when it acutally is... this adds unnecessary time to the development process.
Comment 1 Prakash Rangaraj CLA 2011-04-08 00:58:00 EDT
Moving to JDT.
Comment 2 Michael Rennie CLA 2011-04-08 10:19:01 EDT
This is the expected behavior.

When you create a watch expression you are (in-effect) creating a bookmark for whatever object you want to watch, where the expression maps directly back to the object (i.e. the expression deals with the live Java object). 

In your case you are explicitly calling next() for that iterator object, its no different than if you did the following:

Iterator<File> it = dirs.iterator();
while(it.hasNext()){
   File nextFile = it.next();
   System.out.println(it.next().getName());
}

Marking as INVALID, as this is the intended behavior.