Bug 563271 - [quickfix] enhanced loop quickfix on collection should only be applied when in the body there is no change of the collection triggered
Summary: [quickfix] enhanced loop quickfix on collection should only be applied when i...
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.16   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2020-05-17 13:07 EDT by Carsten Hammer CLA
Modified: 2022-05-24 11:53 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Carsten Hammer CLA 2020-05-17 13:07:58 EDT
When in the body of a loop the collection the loop is iterating on is changed then an access using a loop counter is maybe wrong but does not throw an java.util.ConcurrentModificationException.
The enhanced loop quickfix changes the access to using the iterator build in to the collection object. Using the iterators delete method is working fine but not the collections delete. Depending on which Collection is used after the quickfix is applied the code is still running.
It would be great if the quickfix could sort out some of the problems that can be introduced by either 

1) suggesting a collection change to one of the concurrent or specialized variants 
2) adding a comment explaining the situation
3) changing a collection delete to a iterator delete (is this possible?)
4) stay away from a refactoring if the body or a method called from the body changes the original collection (is this possible to find out on the AST?)

Real world sample code is available in many parts of eclipse source code. 
I just created a fresh sample of a enhanced loop quickfix to see how such problems look like:
https://git.eclipse.org/r/#/c/163148/
Have a look on the listener changes of TextViewer.java

Such changes have caused issues in the past.
see https://bugs.eclipse.org/bugs/show_bug.cgi?id=558510

Another sample:
https://git.eclipse.org/r/#/c/153258/

It would be cool if the enhanced loop quickfix could be made smart enough to cover some of the problems potentially caused by such a change.
Comment 1 Carsten Hammer CLA 2020-05-26 04:17:22 EDT
see https://bugs.eclipse.org/bugs/show_bug.cgi?id=563562 for more samples
Comment 2 Eclipse Genie CLA 2022-05-24 11:53:43 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.