XMLEntityScanner.peekChar 从 HttpRequest 读取 XML 时出现 ArrayIndexOutOfBoundsException

发布于 2024-07-07 20:50:29 字数 2254 浏览 10 评论 0原文

我正在从 Servlet doPost() 中的 HttpServletRequest 读取 XML 数据,并将 Reader 从 req.getReader() 传递到 JAXB 解组器。 我尝试了几种不同的输入 XML,但总是遇到此异常。

SEVERE: Servlet.service() for servlet RESTPhotoAdmin threw exception
java.lang.ArrayIndexOutOfBoundsException: 8192
        at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.peekChar(XMLEntityScanner.java:491)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2672)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:647)
        at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:508)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
        at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)
        at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
        at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
        at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:195)
        at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:168)
        at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:137)
        at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:194)
        at com.cantorva.gigcalendar.servlets.rest.RESTPhotoAdmin.doPost(RESTPhotoAdmin.java:41)

这仅发生在我的 Live Web 服务器上,而不发生在本地开发计算机上。 无论输入是什么(尽管我只尝试了大约 90k 个输入),堆栈跟踪的消息部分始终显示“8192”。 我查找了 XMLEntityScanner.java 第 491 行,可以看到正在读取一个缓冲区,并且该缓冲区确实是一个数组。 对我来说,无法使用从零开始的索引 8192 读取 8k 缓冲区是有道理的,所以这一定是一个错误 - 但原因是什么,我能做什么?


我问这个问题已经通过大量的侦探工作找到了答案。 我想为下一个可怜的家伙省去麻烦,因为 Apache 已经拒绝修复它。

I'm reading XML data from the HttpServletRequest in my servlets doPost() and passing the Reader from req.getReader() to a JAXB unmarshaller. I've tried a couple of different input XMLs but I always get this exception.

SEVERE: Servlet.service() for servlet RESTPhotoAdmin threw exception
java.lang.ArrayIndexOutOfBoundsException: 8192
        at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.peekChar(XMLEntityScanner.java:491)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2672)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:647)
        at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:508)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
        at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)
        at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
        at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
        at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:195)
        at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:168)
        at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:137)
        at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:194)
        at com.cantorva.gigcalendar.servlets.rest.RESTPhotoAdmin.doPost(RESTPhotoAdmin.java:41)

This only happens on my Live web server not on the local development machine. Whatever the input is (though I only tried approx 90k inputs) the message portion of the stack trace always reads "8192". I looked up XMLEntityScanner.java line 491 and can see a buffer being read, and the buffer is indeed an array. It makes sense to me that an 8k buffer can't be read using a zero based index of 8192 so this must be a bug - but what's the cause and what can I do?


I'm asking this having already found the answer through lots of detective work. I wanted to save the next poor guy the hassle since Apache have already refused to fix it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月依秋水 2024-07-14 20:50:29

我发现了一个不起眼的错误 XERCESJ-1275 它本身是 XERCESJ-1015。 该报告没有提到我的堆栈跟踪,但提到了 ArrayIndexOutOfBoundsException。 线索是关于 0 是来自 Reader 的 read 方法的有效(或有些有效)响应的注释,但根据 JavaDoc,它不是来自 InputStream 的响应。 XMLEntityScanner 假定 0 永远不会出现 - 因此会出现错误。

Michael Glavassevich 对文档的解释不同,并将缺陷标记为无效,但解决方法只是使用 req.getInputStream() 为 Unmarshaller 提供一个 InputStream,而不是 Reader,然后祈祷某些晦涩难懂的部分实现更完美地履行了不同的接口契约 - 他们确实做到了。

I found an obscure bug XERCESJ-1275 which is itself a duplicate of XERCESJ-1015. The report doesn't mention my stack trace, but does mention a ArrayIndexOutOfBoundsException. The clue was the comment about 0 being a valid (or somewhat valid) response from a Reader's read method, but not from an InputStream according to the JavaDoc. XMLEntityScanner assumes that 0 can never occur - thus the error.

Michael Glavassevich interprets the documentation differently and marks the defect invalid, but the work around is simply to supply the Unmarshaller an InputStream using req.getInputStream() rather than a Reader and cross your fingers that some obscure part of the implementation is fulfilling the different interface contracts more perfectly - which they do.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文