Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 342155 - Monitoring an iterator in the "Watch Expressions" window affects the iterator in the actual code
Summary: Monitoring an iterator in the "Watch Expressions" window affects the iterator...
Status: CLOSED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Debug (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Debug-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-07 09:30 EDT by Corey CLA
Modified: 2011-04-08 10:19 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.