码迷,mamicode.com
首页 > 编程语言 > 详细

java.lang.ArrayIndexOutOfBoundsException: 100

时间:2015-12-07 00:42:19      阅读:218      评论:0      收藏:0      [点我收藏+]

标签:xml

在用SaxParser做XML解析的时候碰到如下错误信息:

java.lang.ArrayIndexOutOfBoundsException: 100
        at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.scanLiteral(XMLEntityScanner.java:1145)
        at com.sun.org.apache.xerces.internal.impl.XMLScanner.scanAttributeValue(XMLScanner.java:996)
        at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanAttribute(XMLNSDocumentScannerImpl.java:438)
        at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:254)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2778)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
        at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:117)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
        at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
        at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
        at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:649)
        at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:333)
        at javax.xml.parsers.SAXParser.parse(SAXParser.java:195)
        ..

究其原因是JDK中的XML解析有bug,出错的xml结构中有一个包含100多个换行的tag属性,导致了如上的错误。网上查了一下已经有人发现过这个问题https://bugs.openjdk.java.net/browse/JDK-8080085

,该问题应该在最新的JDK8中已经修复,有待验证。

解决方法:预处理unmarshal的字符串,将多个换行符替换为空字符串

str.replaceAll("[\n|\r\n]{100,}", "")

java.lang.ArrayIndexOutOfBoundsException: 100

标签:xml

原文地址:http://jupiterbee.blog.51cto.com/3364619/1720149

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!