Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 255401 - Parser does not handle duplicate elements properly
Summary: Parser does not handle duplicate elements properly
Status: RESOLVED FIXED
Alias: None
Product: Equinox
Classification: Eclipse Project
Component: p2 (show other bugs)
Version: 3.5   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.5 M4   Edit
Assignee: John Arthorne CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-11-14 15:46 EST by Andrew Cattle CLA
Modified: 2008-11-24 08:19 EST (History)
1 user (show)

See Also:


Attachments
artifacts.xml with duplicate elements (1.78 KB, text/xml)
2008-11-14 15:46 EST, Andrew Cattle CLA
no flags Details
Potential fix (needs more testing) (1.54 KB, text/plain)
2008-11-18 13:52 EST, John Arthorne CLA
no flags Details
Adds test case for a duplicate element (2.75 KB, patch)
2008-11-19 10:35 EST, Andrew Cattle CLA
john.arthorne: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Cattle CLA 2008-11-14 15:46:05 EST
Created attachment 117942 [details]
artifacts.xml with duplicate elements

I was creating some invalid xml files for use in some test cases I'm writing and I noticed that if I include a duplicate element (such as a second <mappings> for an artifact repository) the parser treats the duplicate's closing statement (</mappings>) as the end of the parse.

Using the attached artifacts.xml you can see that the file is parsed properly up until the second declaration of <mappings>. This element is correctly identified as a duplicate element. Similarly, the following 3 "rule" elements are properly recognized as invalid. However, noticed that the parse then exits before reaching the "artifacts" element immediately after the </mappings> without any errors.

A similar issue is if you remove the second "</mappings>" from the artifacts.xml, you receive the following error message:
[Fatal Error] :32:3: The element type "mappings" must be terminated by the matching end-tag "</mappings>".
However, in this case the "artifacts" element is parsed.
Comment 1 Andrew Cattle CLA 2008-11-17 09:29:49 EST
Upon reflection I think I should clarify my position on the error message when the duplicate element is not closed.

First, I don't think the error message is accurate. To me, a fatal error means the program can't continue, where in this case it does.

Second, and more importantly, I think this issue is most likely a side effect of duplicate closing elements not being handled correctly. This is why I included it in the bug report.
Comment 2 John Arthorne CLA 2008-11-18 13:52:12 EST
Created attachment 118166 [details]
Potential fix (needs more testing)

Since we are treating duplicate elements as a warning, we should add an IgnoringHandler that will just process and skip the duplicate element.
Comment 3 Andrew Cattle CLA 2008-11-19 09:11:19 EST
The patch seems to work fine for my purposes, but I agree that we'd need some more extensive testing.

Also, this fixes the other issue of the missing closing element saying there was a fatal error and not failing. Now it gives the same error and throws a ProvisionException
Comment 4 Andrew Cattle CLA 2008-11-19 10:35:15 EST
Created attachment 118267 [details]
Adds test case for a duplicate element

Place the XML file I attached earlier in /testData/bug255401/

The test case verifies the patch by ensuring that the artifacts included in the XML (below the duplicate's closing element) are actually parsed.

As for the missing closing on the duplicate element not actually causing a fatal error... I was wrong on that one. Turns out the exception was being caught in my code and I just didn't notice it. I have not included test cases for that issue.
Comment 5 Andrew Cattle CLA 2008-11-19 10:38:41 EST
I should add that John's patch modifies a part of the parser all other parsers inherit from, so I don't think we need to worry about testing this error on individual types of repositories.
Comment 6 John Arthorne CLA 2008-11-20 16:25:48 EST
Thanks Andrew. Assigning to myself to release the fix and tests.
Comment 7 John Arthorne CLA 2008-11-21 17:41:29 EST
Thanks Andrew, fix released. I merged the test into ArtifactRepositoryManagerTest rather than creating a new test class. 

Watch out for copyright statements (and other cruft) when you copy files... you added a new test class but the copyright was for different companies, which I assume came from another class.
Comment 8 Andrew Cattle CLA 2008-11-24 08:19:05 EST
Sorry about that. I'll be more careful in the future.