Community
Participate
Working Groups
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.
Moving to JDT.
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.