... until the collector arrives ...

This "blog" is really just a scratchpad of mine. There is not much of general interest here. Most of the content is scribbled down "live" as I discover things I want to remember. I rarely go back to correct mistakes in older entries. You have been warned :)

2006-02-23

XMLBeans vs HTTP Requests

I saw a strange problem where one of the XMLBeans parse functions failed intermittently when parsing the input stream of an HTTP request.  The exception is:

Caused by: org.xml.sax.SAXParseException: Unexpected end of file after null
	at com.bluecast.xml.Piccolo.reportFatalError(Piccolo.java:1003)
	at com.bluecast.xml.Piccolo.reportFatalError(Piccolo.java:990)
	at com.bluecast.xml.Piccolo.yyerror(Piccolo.java:1302)
	at com.bluecast.xml.Piccolo.yyparse(Piccolo.java:1403)
	at com.bluecast.xml.Piccolo.parse(Piccolo.java:702)
	at com.bea.xbean.store.Root$SaxLoader.load(Root.java:735)
	... 29 more

A quick web search revealed that others had hit this too:

Apache JIRA issue XMLBEANS-226: Exception "Unexpected end of file after null"

The JIRA issue notes that the problem is in the Piccolo parser.  Apparently, that parser does not close the input stream once parsing is complete.  However, it does close the stream the next time you do a parse (which may not happen for an indefinite period of time).  In the absence of a fix from the Piccolo team, the workaround is to close the input stream yourself.  Unfortunately, that causes problems in a subsequent parse because it will attempt to close the stream again (throwing another exception).  Thus, you must wrap the stream with a class that overrides the close method to be tolerant of multiple closes.  That workaround works.

Blog Archive