Question

I'm getting the error in the title occasionally from a process the parses lots of XML files.

The files themselves seem OK, and running the process again on the same files that generated the error works just fine.

The exception occurs on a call to XMLReader.parse(InputStream is)

Could this be a bug in the parser (I use piccolo)? Or is it something about how I open the file stream?

No multithreading is involved.

Piccolo seemed like a good idea at the time, but I don't really have a good excuse for using it. I will to try to switch to the default SAX parser and see if that helps.

Update: It didn't help, and I found that Piccolo is considerably faster for some of the workloads, so I went back.

Was it helpful?

Solution

I should probably tell the end of this story: it was a stupid mistake. There were two processes: one that produces XML files and another that reads them. The reader just scans the directory and tries to process every new file it sees.

Every once in a while, the reader would detect a file before the producer was done writing, and so it legitimately raised an exception for "Unexpected end of file". Since we're talking about small files here, this event was pretty rare. By the time I came to check, the producer would already finish writing the file, so to me it seemed like the parser was complaining for nothing.

I wrote "No multithreading was involved". Obviously this was very misleading.

One solution would be to write the file elsewhere and move it to the monitored folder only after it was done. A better solution would be to use a proper message queue.

OTHER TIPS

I'm experiencing something similar with Picolo under XMLBeans. After a quick Google, I came across the following post:

XMLBEANS-226 - Exception "Unexpected end of file after null"

The post states that use of the Apache Commons (v1.4 onwards) class org.apache.commons.io.input.AutoCloseInputStream may resolve this exception (not tried it myself, apologies).

Is this a multithreaded scenario? I.e. do you parse more than one at the same time.

Any particular reason you do not use the default XML parser in the JRE?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top