org.xml.sax.SAXParseException: Premature end of file for *VALID* XML

前端 未结 7 767
梦如初夏
梦如初夏 2020-12-15 02:45

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

7条回答
  •  失恋的感觉
    2020-12-15 03:06

    This exception only happens if you are parsing an empty String/empty byte array.

    below is a snippet on how to reproduce it:

    String xml = ""; // <-- deliberately an empty string.
    ByteArrayInputStream xmlStream = new java.io.ByteArrayInputStream(xml.getBytes());
    Unmarshaller u = JAXBContext.newInstance(...)
    u.setSchema(...);
    u.unmarshal( xmlStream ); // <-- here it will fail
    

提交回复
热议问题