Bug 226918 - [jsr199] the standard java file manager returned by the Eclipse compiler does not accept non-modifiable iterators as remaining arg to JavaFileManager#handleOption
Summary: [jsr199] the standard java file manager returned by the Eclipse compiler does...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 3.4 M7   Edit
Assignee: Maxime Daniel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-04-14 08:49 EDT by Maxime Daniel CLA
Modified: 2008-04-28 10:26 EDT (History)
2 users (show)

See Also:


Attachments
Tentative fix + test case (6.21 KB, patch)
2008-04-15 03:00 EDT, Maxime Daniel CLA
no flags Details | Diff
Fix + test cases (10.89 KB, patch)
2008-04-16 03:22 EDT, Maxime Daniel CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Maxime Daniel CLA 2008-04-14 08:49:25 EDT
I20080330-1350

Released (inactive) test case org.eclipse.jdt.compiler.tool.tests.CompilerInvocationTests#007.

Considering the boolean handleOption(String current, Iterator<String> remaining)
method, the eclipse compiler:
- does not support a remaining parameter backed by a non-modifiable iterator, while javac does; must be a different interpretation of the meaning for the consumption of remaining items: javac probably does next on the iterator, while ecj (according to sources) attempts a remove;
- consumes one more item than javac (ecj considers that current is also the first item in remaining, while javac considers it is not); reading the javadoc for handleOption, I believe that remaining is only expected to start with the arguments for current, if any.
Comment 1 Olivier Thomann CLA 2008-04-14 09:44:03 EDT
The javadoc is:
    Handles one option. If current is an option to this file manager it will consume any arguments to that option from remaining and return true, otherwise return false.

I don't see where it is said that remaining is only expected to start with the
arguments for current. The arguments are supposed to be consumed when arguments are expected.
Comment 2 Maxime Daniel CLA 2008-04-15 02:58:36 EDT
At least the javadoc does not say it will consume anything but 'arguments to that option'.
However, my second assertion is wrong (there is only one call to next() in the code - which means that the iterator is not 'nexted' more than needed - I was blindsided  by the call to remove). Which would mean that, as far as shifting the iterator is concerned, the right behavior is implemented.
It still remains true that passing an Iterator that does not support the remove operation throws an IllegalStateException, which I believe is not acceptable, especially since the default standard Java file manager does not make this tilt.
Aligned the title accordingly.
Comment 3 Maxime Daniel CLA 2008-04-15 03:00:52 EDT
Created attachment 96044 [details]
Tentative fix + test case

Would need more test coverage (only testing the -d option so far).
Comment 4 Olivier Thomann CLA 2008-04-15 08:44:30 EDT
(In reply to comment #2)
> It still remains true that passing an Iterator that does not support the remove
> operation throws an IllegalStateException, which I believe is not acceptable,
> especially since the default standard Java file manager does not make this
> tilt.
My claim is that this is not specified. It could be an implementation detail. The "spec" says "consume". From a spec point of view, this is weak as it doesn't say how to consume the elements in the iterator.
I choose to remove the elements to make sure that we don't process them twice. The file manager "removes" the options that it knows how to handle them and leave the remaining ones for other to process.
Comment 5 Maxime Daniel CLA 2008-04-15 09:15:02 EDT
The API only gives us an Iterator. Not all Iterator-s support the remove operation and, unless the APIs tells the client that only some Iterator-s are supported, he is free to use any Iterator he wishes. Hence I believe that the spec, while it does not insist so, makes clear that we should not tilt on any Iterator (as long as the options they carry are OK with us).
Another angle from which we could consider the question is the following: if I use next() upon an Iterator, how could I go back and process the same element again? This would need that I go to something more sophisticated (a two-ways cursor or the underlying storage), which I wouldn't do inadvertently.
Comment 6 Maxime Daniel CLA 2008-04-16 03:22:39 EDT
Created attachment 96204 [details]
Fix + test cases

Same fix, with improved test coverage (leverages the options lists of CompilerToolTests).
Comment 7 Maxime Daniel CLA 2008-04-16 03:32:11 EDT
Released for 3.4 M7.

Kent please yell if anything looks odd.
Comment 8 David Audel CLA 2008-04-28 10:26:17 EDT
Verified for 3.4M7 using I20080427-2000