Issue Details (XML | Word | Printable)

Key: BATCH-761
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Robert Kasanicky
Reporter: Ian Brandt
Votes: 0
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
Spring Batch

StaxEventItemWriter writes extra end document tag with Woodstox 3.2.6

Created: 05/Aug/08 01:10 PM   Updated: 25/Sep/08 05:02 AM   Resolved: 25/Sep/08 05:02 AM
Component/s: Infrastructure
Affects Version/s: 1.1.0
Fix Version/s: 1.1.2, 2.0.0.M1

Time Tracking:
Original Estimate: 0.12d
Original Estimate - 0.12d
Remaining Estimate: 0d
Remaining Estimate - 0d
Time Spent: 0.12d
Time Spent - 0.12d

File Attachments: 1. Text File StaxEventItemWriter.Woodstox.patch (0.8 kB)



 Description  « Hide
Woodstox 3.2.6 (current stable)'s StaxEventWriter implementation automatically writes end tags and end document tags that it detects as still open on close. When StaxEventItemWriter wraps Woodstox with a NoStartEndDocumentStreamWriter for the chunk writer (eventWriter), and another Woodstox instance for the document writer (delegateEventWriter), the result is two end document tags being written. This is because even though the NoStartEndDocumentStreamWriter prevents the end document event from being written to the chunk writer, it writes the end document tag on close() anyway, on top of the one being written by StaxEventItemWriter.endDocument(delegateEventWriter) itself.

Here's the relevant stack trace:

Thread [main] (Suspended)
com.ctc.wstx.sw.SimpleNsStreamWriter(com.ctc.wstx.sw.BaseStreamWriter).finishDocument() line: 1672
com.ctc.wstx.sw.SimpleNsStreamWriter(com.ctc.wstx.sw.BaseStreamWriter).close() line: 288
com.ctc.wstx.evt.WstxEventWriter.close() line: 237
org.springframework.batch.item.xml.stax.NoStartEndDocumentStreamWriter(org.springframework.batch.item.xml.stax.AbstractEventWriterWrapper).close() line: 32
org.springframework.batch.item.xml.StaxEventItemWriter.close(org.springframework.batch.item.ExecutionContext) line: 376

This was captured with Spring 1.1.0, but I diff'ed StaxEventItemWriter and NoStartEndDocumentStreamWriter for 1.1.0 vs. 1.1.1 in FishEye, and am not seeing anything that would change the behavior.


Ian Brandt added a comment - 05/Aug/08 01:52 PM
Corrections to my initial description:

1) "Woodstox 3.2.6 (current stable)'s *XMLEventWriter* implementation..."

2) There is only one Woodstox WstxEventWriter instance. The NoStartEndDocumentStreamWriter eventWriter is a second handle wrapping the XMLEventWriter delegateEventWriter's WstxEventWriter instance.

Ian Brandt added a comment - 05/Aug/08 05:09 PM
Quick and dirty workaround patch against 1.1.1. Works for me, YMMV, etc. Sorry for no test case goodness, up against a deadline.

Ian Brandt made changes - 05/Aug/08 05:09 PM
Field Original Value New Value
Attachment StaxEventItemWriter.Woodstox.patch [ 14502 ]
Ian Brandt added a comment - 06/Aug/08 02:38 PM
Forgot to mention that the 3.9.x (a.k.a. pre-4.0) releases of Woodstox contain internal refactoring such that "com.ctc.wstx.evt.WstxEventWriter" no longer exists, hence my attached patch won't trap this bug for the post 3.2 series. I didn't look into whether it was just repackaged, or replaced with something else entirely. I'm also not sure whether they've changed their automatic tag closing behavior in the 3.9 series, such that the workaround would even still be necessary.

Robert Kasanicky added a comment - 07/Aug/08 09:06 AM
Making the private endDocument(XMLWriter) protected should allow users to fix the issue cleanly themselves by subclassing.

Robert Kasanicky made changes - 07/Aug/08 09:06 AM
Fix Version/s 1.1.2 [ 11077 ]
Original Estimate 0.12d [ 3600 ]
Remaining Estimate 0.12d [ 3600 ]
Fix Version/s 2.0.0.M1 [ 11036 ]
Assignee Robert Kasanicky [ robert.kasanicky ]
Ian Brandt added a comment - 07/Aug/08 03:44 PM
Interesting, though wouldn't making endDocument protected create a bit of a coupling/versioning problem, and ultimately just "pass the buck" for this issue to Spring Batch users? I'll explain...

As far as I know there are only three Java StAX implementations in common usage: the BEA RI, Sun's SJSXP, and Woodstox. I have no idea what the adoption ratio of each is, but Woodstox has been a formidable implementation for some time. Sub-classing would mean that anyone and everyone using StaxEventItemWriter with Woodstox would have to extend it with a WstxStaxEventItemWriter of sorts that overrides endDocument. The downsides are: 1) they'll need to know to do this in the first place, 2) more code for them to maintain, 3) perhaps worst of all is that all that code in the wild will be coupled to an implementation detail of StaxEventItemWriter in a manner that is outside of Spring Batch's control. My solution may not be pretty, but the ugliness is contained rather than propagated.

Really I think the best solution is that Woodstox should make this auto-closing behavior an optional feature of the parser configurable by runtime properties. (See: http://woodstox.codehaus.org/ConfiguringStreamWriters). Then my patch would look more like:

XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
if (outputFactory.isPropertySupported("com.ctc.wstx.autoCloseElements")) {
outputFactory.setProperty("com.ctc.wstx.autoCloseElements", false);
}

A bit cleaner than getClass().getName().equals, and it can be done outside Spring Batch or in (though I still think inside is more user friendly). If you want to hold off for a bit on opening up endDocument I can go lobby for such a parser option in Woodstox 3.2.7?

2039 by  robokaso (1 file)
11/Aug/08 03:52 AM (17 months, 20 days ago)
RESOLVED - BATCH-761: StaxEventItemWriter writes extra end document tag with Woodstox 3.2.6

made endDocument(..) protected
spring-batch: trunk/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemWriter.java 2039 history download (+16 -9) diffs

2040 by  robokaso (1 file)
11/Aug/08 04:06 AM (17 months, 20 days ago)
RESOLVED - BATCH-761: StaxEventItemWriter writes extra end document tag with Woodstox 3.2.6

made endDocument(..) protected
spring-batch: branches/1.1.x/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemWriter.java 2040 history download (+19 -12) diffs

Robert Kasanicky added a comment - 11/Aug/08 04:15 AM
I've made the endDocument protected - how end tag is written is kind of a hack anyway, so it makes sense to allow users to tweak the behavior.

@Ian: I don't like the idea of putting Stax implementation specific code into SB codebase, but if this is standard Woodstox behavior (consistent among versions) I guess we could do that. The "isPropertySupported" approach seems sensible if it would fix Woodstox trouble in general.

Robert Kasanicky logged work - 11/Aug/08 07:13 AM
Time Worked: 0.12d
<No comment>
Robert Kasanicky made changes - 11/Aug/08 07:13 AM
Remaining Estimate 0.12d [ 3600 ] 0d [ 0 ]
Time Spent 0.12d [ 3600 ]
Robert Kasanicky added a comment - 11/Aug/08 07:15 AM
For now resolving the issue with the advice to override the protected endDocument method when used with Woodstox. If you can suggest a generic Woodstox fix please drop a comment and we can consider doing more.

Robert Kasanicky made changes - 11/Aug/08 07:15 AM
Status Open [ 1 ] Resolved [ 5 ]
Resolution Fixed [ 1 ]
Tatu Saloranta added a comment - 04/Sep/08 08:03 PM
Just noticed this entry, and thought I can as well add the Woodstox jira entry:

http://jira.codehaus.org/browse/WSTX-165

(too bad I didn't notice it few days ago, before 3.2.7 release, but it'll get into 3.2.8 :) )


Dave Syer made changes - 21/Sep/08 11:38 AM
Comment [ http://www.gnn.com.br/forum/showthread.php?t=1000087664
http://www.gnn.com.br/forum/showthread.php?t=1000087663
http://www.gnn.com.br/forum/showthread.php?t=1000087662
http://www.gnn.com.br/forum/showthread.php?t=1000087661
http://www.gnn.com.br/forum/showthread.php?t=1000087660
http://www.gnn.com.br/forum/showthread.php?t=1000087659
http://www.gnn.com.br/forum/showthread.php?t=1000087658
http://www.gnn.com.br/forum/showthread.php?t=1000087657
http://www.gnn.com.br/forum/showthread.php?t=1000087655
http://www.gnn.com.br/forum/showthread.php?t=1000087654
http://www.gnn.com.br/forum/showthread.php?t=1000087653
http://www.gnn.com.br/forum/showthread.php?t=1000087652
http://www.gnn.com.br/forum/showthread.php?t=1000087651
http://www.gnn.com.br/forum/showthread.php?t=1000087650
http://www.gnn.com.br/forum/showthread.php?t=1000087649
http://www.gnn.com.br/forum/showthread.php?t=1000087647
http://www.gnn.com.br/forum/showthread.php?t=1000087646
http://www.gnn.com.br/forum/showthread.php?t=1000087645
http://www.gnn.com.br/forum/showthread.php?t=1000087643
http://www.gnn.com.br/forum/showthread.php?t=1000087642
http://www.gnn.com.br/forum/showthread.php?t=1000087640
http://www.gnn.com.br/forum/showthread.php?t=1000087639
http://www.gnn.com.br/forum/showthread.php?t=1000087638
http://www.gnn.com.br/forum/showthread.php?t=1000087637
http://www.gnn.com.br/forum/showthread.php?t=1000087636
http://www.gnn.com.br/forum/showthread.php?t=1000087635
http://www.gnn.com.br/forum/showthread.php?t=1000087633
http://www.gnn.com.br/forum/showthread.php?t=1000087554
http://www.gnn.com.br/forum/showthread.php?t=1000087553
http://www.gnn.com.br/forum/showthread.php?t=1000087551
http://www.gnn.com.br/forum/showthread.php?t=1000087550
http://www.gnn.com.br/forum/showthread.php?t=1000087548
http://www.gnn.com.br/forum/showthread.php?t=1000087547
http://www.gnn.com.br/forum/showthread.php?t=1000087546
http://www.gnn.com.br/forum/showthread.php?t=1000087545
http://www.gnn.com.br/forum/showthread.php?t=1000087632
http://www.gnn.com.br/forum/showthread.php?t=1000087631
http://www.gnn.com.br/forum/showthread.php?t=1000087630
http://www.gnn.com.br/forum/showthread.php?t=1000087629
http://www.gnn.com.br/forum/showthread.php?t=1000087628
http://www.gnn.com.br/forum/showthread.php?t=1000087627
http://www.gnn.com.br/forum/showthread.php?t=1000087625
http://www.gnn.com.br/forum/showthread.php?t=1000087624
http://www.gnn.com.br/forum/showthread.php?t=1000087623
http://www.gnn.com.br/forum/showthread.php?t=1000087622
http://www.gnn.com.br/forum/showthread.php?t=1000087621
http://www.gnn.com.br/forum/showthread.php?t=1000087620
http://www.gnn.com.br/forum/showthread.php?t=1000087618
http://www.gnn.com.br/forum/showthread.php?t=1000087617
http://www.gnn.com.br/forum/showthread.php?t=1000087616
http://www.gnn.com.br/forum/showthread.php?t=1000087615
http://www.gnn.com.br/forum/showthread.php?t=1000087614
http://www.gnn.com.br/forum/showthread.php?t=1000087613
http://www.gnn.com.br/forum/showthread.php?t=1000087611
http://www.gnn.com.br/forum/showthread.php?t=1000087610
http://www.gnn.com.br/forum/showthread.php?t=1000087609
http://www.gnn.com.br/forum/showthread.php?t=1000087608
http://www.gnn.com.br/forum/showthread.php?t=1000087607
http://www.gnn.com.br/forum/showthread.php?t=1000087605
http://www.gnn.com.br/forum/showthread.php?t=1000087604
http://www.gnn.com.br/forum/showthread.php?t=1000087603
http://www.gnn.com.br/forum/showthread.php?t=1000087602
http://www.gnn.com.br/forum/showthread.php?t=1000087601
http://www.gnn.com.br/forum/showthread.php?t=1000087600
http://www.gnn.com.br/forum/showthread.php?t=1000087599
http://www.gnn.com.br/forum/showthread.php?t=1000087598
http://www.gnn.com.br/forum/showthread.php?t=1000087597
http://www.gnn.com.br/forum/showthread.php?t=1000087596
http://www.gnn.com.br/forum/showthread.php?t=1000087595
http://www.gnn.com.br/forum/showthread.php?t=1000087592
http://www.gnn.com.br/forum/showthread.php?t=1000087591
http://www.gnn.com.br/forum/showthread.php?t=1000087590
http://www.gnn.com.br/forum/showthread.php?t=1000087588
http://www.gnn.com.br/forum/showthread.php?t=1000087587
http://www.gnn.com.br/forum/showthread.php?t=1000087586
http://www.gnn.com.br/forum/showthread.php?t=1000087585
http://www.gnn.com.br/forum/showthread.php?t=1000087584
http://www.gnn.com.br/forum/showthread.php?t=1000087583
http://www.gnn.com.br/forum/showthread.php?t=1000087582
http://www.gnn.com.br/forum/showthread.php?t=1000087581
http://www.gnn.com.br/forum/showthread.php?t=1000087579
http://www.gnn.com.br/forum/showthread.php?t=1000087578
http://www.gnn.com.br/forum/showthread.php?t=1000087577
http://www.gnn.com.br/forum/showthread.php?t=1000087575
http://www.gnn.com.br/forum/showthread.php?t=1000087574
http://www.gnn.com.br/forum/showthread.php?t=1000087573
http://www.gnn.com.br/forum/showthread.php?t=1000087572
http://www.gnn.com.br/forum/showthread.php?t=1000087571
http://www.gnn.com.br/forum/showthread.php?t=1000087570
http://www.gnn.com.br/forum/showthread.php?t=1000087569
http://www.gnn.com.br/forum/showthread.php?t=1000087568
http://www.gnn.com.br/forum/showthread.php?t=1000087567
http://www.gnn.com.br/forum/showthread.php?t=1000087565
http://www.gnn.com.br/forum/showthread.php?t=1000087564
http://www.gnn.com.br/forum/showthread.php?t=1000087561
http://www.gnn.com.br/forum/showthread.php?t=1000087559
http://www.gnn.com.br/forum/showthread.php?t=1000087558
http://www.gnn.com.br/forum/showthread.php?t=1000087557
http://www.gnn.com.br/forum/showthread.php?t=1000087556
http://www.gnn.com.br/forum/showthread.php?t=1000087555 ]
Lucas Ward made changes - 23/Sep/08 07:56 PM
Status Resolved [ 5 ] Closed [ 6 ]
Dave Syer added a comment - 25/Sep/08 05:02 AM
re-opened to remove spam

Dave Syer made changes - 25/Sep/08 05:02 AM
Status Closed [ 6 ] Reopened [ 4 ]
Resolution Fixed [ 1 ]
Dave Syer made changes - 25/Sep/08 05:02 AM
Comment [ http://www.tamilstar.info/forums/index.php?showtopic=158648
http://www.tamilstar.info/forums/index.php?showtopic=158646
http://www.tamilstar.info/forums/index.php?showtopic=158643
http://www.tamilstar.info/forums/index.php?showtopic=158640
http://www.tamilstar.info/forums/index.php?showtopic=158638
http://www.tamilstar.info/forums/index.php?showtopic=158636
http://www.tamilstar.info/forums/index.php?showtopic=158632
http://www.tamilstar.info/forums/index.php?showtopic=158631
http://www.tamilstar.info/forums/index.php?showtopic=158628
http://www.tamilstar.info/forums/index.php?showtopic=158625
http://www.tamilstar.info/forums/index.php?showtopic=158621
http://www.tamilstar.info/forums/index.php?showtopic=158619
http://www.tamilstar.info/forums/index.php?showtopic=158616
http://www.tamilstar.info/forums/index.php?showtopic=158613
http://www.tamilstar.info/forums/index.php?showtopic=158612
http://www.tamilstar.info/forums/index.php?showtopic=158608
http://www.tamilstar.info/forums/index.php?showtopic=158607
http://www.tamilstar.info/forums/index.php?showtopic=158604
http://www.tamilstar.info/forums/index.php?showtopic=158601
http://www.tamilstar.info/forums/index.php?showtopic=158598
http://www.tamilstar.info/forums/index.php?showtopic=158595
http://www.tamilstar.info/forums/index.php?showtopic=158592
http://www.tamilstar.info/forums/index.php?showtopic=158590
http://www.tamilstar.info/forums/index.php?showtopic=158588
http://www.tamilstar.info/forums/index.php?showtopic=158584
http://www.tamilstar.info/forums/index.php?showtopic=158580
http://www.tamilstar.info/forums/index.php?showtopic=158575
http://www.tamilstar.info/forums/index.php?showtopic=158573
http://www.tamilstar.info/forums/index.php?showtopic=158570
http://www.tamilstar.info/forums/index.php?showtopic=158430
http://www.tamilstar.info/forums/index.php?showtopic=158426
http://www.tamilstar.info/forums/index.php?showtopic=158422
http://www.tamilstar.info/forums/index.php?showtopic=158419
http://www.tamilstar.info/forums/index.php?showtopic=158415
http://www.tamilstar.info/forums/index.php?showtopic=158412
http://www.tamilstar.info/forums/index.php?showtopic=158407
http://www.tamilstar.info/forums/index.php?showtopic=158405
http://www.tamilstar.info/forums/index.php?showtopic=158405
http://www.tamilstar.info/forums/index.php?showtopic=158402
http://www.tamilstar.info/forums/index.php?showtopic=158399
http://www.tamilstar.info/forums/index.php?showtopic=158397
http://www.tamilstar.info/forums/index.php?showtopic=158394
http://www.tamilstar.info/forums/index.php?showtopic=158391
http://www.tamilstar.info/forums/index.php?showtopic=158390
http://www.tamilstar.info/forums/index.php?showtopic=158386
http://www.tamilstar.info/forums/index.php?showtopic=158382
http://www.tamilstar.info/forums/index.php?showtopic=158378
http://www.tamilstar.info/forums/index.php?showtopic=158367
http://www.tamilstar.info/forums/index.php?showtopic=158356
http://www.tamilstar.info/forums/index.php?showtopic=158348
http://www.tamilstar.info/forums/index.php?showtopic=158330
http://www.tamilstar.info/forums/index.php?showtopic=158303
http://www.tamilstar.info/forums/index.php?showtopic=158289
http://www.tamilstar.info/forums/index.php?showtopic=158273
http://www.tamilstar.info/forums/index.php?showtopic=158210
http://www.tamilstar.info/forums/index.php?showtopic=157908
http://www.tamilstar.info/forums/index.php?showtopic=157905
http://www.tamilstar.info/forums/index.php?showtopic=157903
http://www.tamilstar.info/forums/index.php?showtopic=157902
http://www.tamilstar.info/forums/index.php?showtopic=157899
http://www.tamilstar.info/forums/index.php?showtopic=157896
http://www.tamilstar.info/forums/index.php?showtopic=157894
http://www.tamilstar.info/forums/index.php?showtopic=157889
http://www.tamilstar.info/forums/index.php?showtopic=157886
http://www.tamilstar.info/forums/index.php?showtopic=157883
http://www.tamilstar.info/forums/index.php?showtopic=157881
http://www.tamilstar.info/forums/index.php?showtopic=157878
http://www.tamilstar.info/forums/index.php?showtopic=157875
http://www.tamilstar.info/forums/index.php?showtopic=157872
http://www.tamilstar.info/forums/index.php?showtopic=157871
http://www.tamilstar.info/forums/index.php?showtopic=157868
http://www.tamilstar.info/forums/index.php?showtopic=157864
http://www.tamilstar.info/forums/index.php?showtopic=157863
http://www.tamilstar.info/forums/index.php?showtopic=157859
http://www.tamilstar.info/forums/index.php?showtopic=157710
http://www.tamilstar.info/forums/index.php?showtopic=157708
http://www.tamilstar.info/forums/index.php?showtopic=157683
http://www.tamilstar.info/forums/index.php?showtopic=157680
http://www.tamilstar.info/forums/index.php?showtopic=157673
http://www.tamilstar.info/forums/index.php?showtopic=157671
http://www.tamilstar.info/forums/index.php?showtopic=157668
http://www.tamilstar.info/forums/index.php?showtopic=157660
http://www.tamilstar.info/forums/index.php?showtopic=157643
http://www.tamilstar.info/forums/index.php?showtopic=157628
http://www.tamilstar.info/forums/index.php?showtopic=157616
http://www.tamilstar.info/forums/index.php?showtopic=157601
http://www.tamilstar.info/forums/index.php?showtopic=157569
http://www.tamilstar.info/forums/index.php?showtopic=157546
http://www.tamilstar.info/forums/index.php?showtopic=157540
http://www.tamilstar.info/forums/index.php?showtopic=157531
http://www.tamilstar.info/forums/index.php?showtopic=157490
http://www.tamilstar.info/forums/index.php?showtopic=157079
http://www.tamilstar.info/forums/index.php?showtopic=157076
http://www.tamilstar.info/forums/index.php?showtopic=157073
http://www.tamilstar.info/forums/index.php?showtopic=157069
http://www.tamilstar.info/forums/index.php?showtopic=157065
http://www.tamilstar.info/forums/index.php?showtopic=157063
http://www.tamilstar.info/forums/index.php?showtopic=157063
http://www.tamilstar.info/forums/index.php?showtopic=157059
http://www.tamilstar.info/forums/index.php?showtopic=157056 ]
Dave Syer made changes - 25/Sep/08 05:02 AM
Resolution Fixed [ 1 ]
Status Reopened [ 4 ] Closed [ 6 ]
Create crucible review for all 2 changesets in