aspose file tools*
The moose likes XML and Related Technologies and the fly likes org.xml.sax.SAXParseException: Premature end of file for valid XML? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "org.xml.sax.SAXParseException: Premature end of file for valid XML?" Watch "org.xml.sax.SAXParseException: Premature end of file for valid XML?" New topic
Author

org.xml.sax.SAXParseException: Premature end of file for valid XML?

Manish Hatwalne
Ranch Hand

Joined: Sep 22, 2001
Posts: 2581

I am getting very strange "Premature end of file." exception for last few days on one of our servers. The same configuration XML works fine on another server. We are using Tomcat 5.0.28 on both these servers. This code has been working for ages (7+ years), only after recent server crash, we faced this problem on one of the servers. There is no change in XML as well as Java parsing code.

The only difference I can see is in Java versions -

Problem Server

java version "1.6.0_16" Java(TM) SE Runtime Environment (build 1.6.0_16-b01) Java HotSpot(TM) 64-Bit Server VM (build 14.2-b01, mixed mode)

Working Server

java version "1.6.0_07" Java(TM) SE Runtime Environment (build 1.6.0_07-b06) Java HotSpot(TM) 64-Bit Server VM (build 10.0-b23, mixed mode)

Here is the Java code that has been working for several years -



And here is the exception.



I have already tried validating XML and found no errors there (updated it from SVN as well). The XML is 108.1 KB in size and comes from local file system.
Any idea where else can I look for the possible problem?

Any pointers would be highly appreciated!

TIA,
- Manish
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10288
    
168

I think the first thing to do would be to make sure that it is indeed picking up the right file and not some stale/invalid version.

[My Blog] [JavaRanch Journal]
Manish Hatwalne
Ranch Hand

Joined: Sep 22, 2001
Posts: 2581

Jaikiran Pai wrote:I think the first thing to do would be to make sure that it is indeed picking up the right file and not some stale/invalid version.


It is picking up the right file. Already checked that!
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
If this was my problem I would use the SAXParseException methods getLineNumber and getColumnNumber when reporting the exception.

These frequently help me to locate completely unexpected weird problems like yours.

Bill
Manish Hatwalne
Ranch Hand

Joined: Sep 22, 2001
Posts: 2581

William Brogden wrote:If this was my problem I would use the SAXParseException methods getLineNumber and getColumnNumber when reporting the exception.

These frequently help me to locate completely unexpected weird problems like yours.

Bill


OK. Let me try this - can I get line & column number even if I pass "Locator" as null? If not, how do I get Locator for this?

Thanks!
- manish
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18986
    
    8

You appear to be assuming that the "file" referred to in the "end of file" message is the XML document. Is it not possible that the "file" in question is a DTD or schema which the document refers to?
Manish Hatwalne
Ranch Hand

Joined: Sep 22, 2001
Posts: 2581

Paul Clapham wrote:You appear to be assuming that the "file" referred to in the "end of file" message is the XML document. Is it not possible that the "file" in question is a DTD or schema which the document refers to?


NO. Unlikely. I am not validating against any schema/DTD.

I should also add that we start 16 jobs through this XML configuration. 12 out of 16 jobs are running fine now, but 4 jobs (despite having valid configuration elements) are just not running and causing parse exception. I have tried moving them up & down the config fine, but just those jobs are having problems. That makes one suspect XML element themselves, but I have carefully examined them and have found that they are absolutely fine.
Manish Hatwalne
Ranch Hand

Joined: Sep 22, 2001
Posts: 2581

William Brogden wrote:If this was my problem I would use the SAXParseException methods getLineNumber and getColumnNumber when reporting the exception.

These frequently help me to locate completely unexpected weird problems like yours.

Bill


On my local machine, I deliberately introduced an XML error and checked it with the code using SAXParseException, but I found that it didn't give me line number or column number (I thought so) as I didn't have a valid Locator object there.

Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10288
    
168

Can you post the actual xml contents, including the first few lines in there?
Manish Hatwalne
Ranch Hand

Joined: Sep 22, 2001
Posts: 2581

Jaikiran Pai wrote:Can you post the actual xml contents, including the first few lines in there?


I am afraid, I can't. Lot of sensitive information there...
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10288
    
168

How is the InputSource that's being passed to the parser, being created in your application? What does that code look like? Most likely the problem lies there and not in the parsing part.
Manish Hatwalne
Ranch Hand

Joined: Sep 22, 2001
Posts: 2581

Jaikiran Pai wrote:How is the InputSource that's being passed to the parser, being created in your application? What does that code look like? Most likely the problem lies there and not in the parsing part.


This is how InputSource is getting created -

Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10288
    
168

Before passing on the InputSource to the parser, try printing out its contents, something like:


That's just a sample code which I haven't tested. Also, after you read that InputSource, you won't be able to pass it on to the parser since you already will have read the contents of that source.
Manish Hatwalne
Ranch Hand

Joined: Sep 22, 2001
Posts: 2581

I found the problem and fixed it.
It was elsewhere in another XML...will type details tomorrow. :-)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: org.xml.sax.SAXParseException: Premature end of file for valid XML?