Bug 54068

Summary: Web fragment sorting incorrectly detects circular reference
Product: Tomcat 7 Reporter: Dennis Homann <dennis.homann>
Component: CatalinaAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 7.0.32   
Target Milestone: ---   
Hardware: PC   
OS: All   
Attachments: Test case implementation

Description Dennis Homann 2012-10-30 05:30:27 UTC
Created attachment 29522 [details]
Test case implementation

The implementation of web fragment sorting with relative ordering constraints may detect circular references, even though there is no such circle. 

This occurrence of this bug depends on the iteration order of the input map.

Consider the attached test case, defining a simple chain of three web fragments:
* web fragments a, b, c, with relative constraints "b after a", "c after b".
* expected result: a, b, c
* actual result: 

Testcase: testOrderWebFragmentsRelative4 took 0,002 sec
        Caused an ERROR
Fragment relative ordering contains circular references. Thsi can be resolved by using absolute ordering in web.xml.
java.lang.IllegalArgumentException: Fragment relative ordering contains circular references. Thsi can be resolved by using absolute ordering in web.xml.
        at org.apache.catalina.deploy.WebXml.orderWebFragments(WebXml.java:2190)
        at org.apache.catalina.deploy.TestWebXmlOrdering.testOrderWebFragmentsRelative4(TestWebXmlOrdering.java:268)

Workaround: use absolute ordering.

Details:
* Java 1.7.0_07
Comment 1 Mark Thomas 2012-10-30 08:38:33 UTC
Comment on attachment 29522 [details]
Test case implementation

Fix MIME type
Comment 2 Mark Thomas 2012-10-31 22:07:30 UTC
What a lovely can of worms that was. All my own fault since I wrote the broken algorithm in the first place.

I have re-written the sorting algorithm to address the issue identified in this report and a handful of other problems that emerged as I started to look for ways to break the existing algorithm.

The test cases for relative ordering have be re-written so they test all 720 possible combinations of input order for each test and I have increased the number of test cases including several to cover the ordering highlighted in this test case.

The fix has been made to trunk and 7.0.x and will be included in 7.0.33 onwards.
Comment 3 Dennis Homann 2012-10-31 22:10:43 UTC
Great, thank you!