Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 352683 - AbstractServerAction's run method incorrectly assumes iterator will have elements
Summary: AbstractServerAction's run method incorrectly assumes iterator will have elem...
Status: RESOLVED FIXED
Alias: None
Product: WTP ServerTools
Classification: WebTools
Component: wst.server (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.2.5   Edit
Assignee: Steven Hung CLA
QA Contact: Angel Vera CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-20 17:54 EDT by Steven Hung CLA
Modified: 2017-10-11 16:36 EDT (History)
1 user (show)

See Also:


Attachments
Initial patch (949 bytes, patch)
2011-07-20 17:55 EDT, Steven Hung CLA
eyuen7: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Steven Hung CLA 2011-07-20 17:54:44 EDT
Build Identifier: 

While running ad-hoc testing on eclipse, the .log file had displayed the error:

java.util.NoSuchElementException
    at java.util.AbstractList$SimpleListIterator.next(Unknown Source)
    at org.eclipse.wst.server.ui.internal.view.servers.AbstractServerAction.run(Unknown Source)
    at org.eclipse.ui.actions.RetargetAction.run(Unknown Source)
    at org.eclipse.ui.navigator.CommonNavigatorManager$3.open(Unknown Source)
    at org.eclipse.ui.OpenAndLinkWithEditorHelper$InternalListener.open(Unknown Source)
    at org.eclipse.jface.viewers.StructuredViewer$2.run(Unknown Source)
    at org.eclipse.core.runtime.SafeRunner.run(Unknown Source)
    at org.eclipse.ui.internal.JFaceUtil$1.run(Unknown Source)
.......

Since it was ad-hoc, I have been unable to reproduce the exact steps to throw that error.

In org.eclipse.wst.server.ui.internal.view.servers.AbstractServerAction.run(), it should not be assumed that the iterator will have a next element.



Reproducible: Always
Comment 1 Steven Hung CLA 2011-07-20 17:55:45 EDT
Created attachment 200040 [details]
Initial patch
Comment 2 Steven Hung CLA 2011-07-20 18:01:35 EDT
I have attached a patch, that will return from the method to avoid the NoSuchElementException if the iterator has no elements.

Tests run:
1. If the iterator has elements - the code will continue as usual after the check
2. If the iterator does not have an element - this was reproduced by temporarily making Iterator iterator = new StructuredSelection().iterator(). The iterator will have no next element and the method will exit silently (not throw an exception or write a trace) and not have a NoSuchElementException exception
Comment 3 Elson Yuen CLA 2011-07-21 15:31:21 EDT
Changes looks good with sufficient test coverage. 

Code committed 32M and 33M.  One minor change to the original patch to update the copyright statement.
Comment 4 Elson Yuen CLA 2011-07-21 15:43:29 EDT
Code released to HEAD.
Comment 5 Elson Yuen CLA 2011-07-22 13:57:52 EDT
Code released to 32M and 33M.
Comment 6 Eclipse Genie CLA 2017-10-11 16:36:38 EDT
New Gerrit change created: https://git.eclipse.org/r/109052