Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 313249 - XMLResource cannot save an empty resource
Summary: XMLResource cannot save an empty resource
Status: RESOLVED WONTFIX
Alias: None
Product: EMF
Classification: Modeling
Component: XML/XMI (show other bugs)
Version: 2.5.0   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Ed Merks CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-17 17:51 EDT by Bryan Hunt CLA
Modified: 2010-05-17 18:16 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 Bryan Hunt CLA 2010-05-17 17:51:41 EDT
If you create an XMLResource and then try to save it without adding an object to its contents, you will get a BasicEList$BasicIndexOutOfBoundsException.  It appears the problem is that in XMLSaveImpl line 592 calls wreiteTopObjects(contents) when contents.size() != 1 which then calls contents.get(0) which throws the exception because contents.size() == 0.
Comment 1 Ed Merks CLA 2010-05-17 18:04:21 EDT
SAX can't parse an empty file so it's good for save to fail one way or another.
Comment 2 Bryan Hunt CLA 2010-05-17 18:07:37 EDT
In this case, it doesn't make sense to write a header with empty content?  If that's the case, it might be nice to have a better exception ... something like:

if(contents.isEmpty())
  throw new IOException("Cannot save a resource with no contents");
Comment 3 Ed Merks CLA 2010-05-17 18:16:24 EDT
No, an XML resource must have a single root element.  For all I know, someone already catches an index out of bounds exception so while I agree that a descriptive message would be a marginal improvement, the current failure is pretty obvious as well.  In fact, this is really a smaller problem than the fact that if you have more than one element, only the first is saved and the rest are silently ignored...