SAXParseException XML-20221文本中的char无效 [英] SAXParseException XML-20221 Invalid char in text
问题描述
对于独立的Java应用程序,我们看到非常罕见的错误,其中包含有效XML内容的字符串导致JAXB抛出异常,例如:
For a standalone Java application, we are seeing very rare errors where Strings containing valid XML content are causing JAXB to throw exceptions like:
javax.xml.bind.UnmarshalException
- with linked exception:
[org.xml.sax.SAXParseException:
<Line 1, Column 129>: XML-20221: (Fatal Error) Invalid char in text.]
这是一个非常古老的Java应用程序,是为旧版本的Java,我们有一个现有的依赖项:
This is a very old Java application, that was written for an older version of Java, and we have an existing dependency:
<dependency>
<groupId>com.oracle</groupId>
<artifactId>xdb-xmlparser</artifactId>
<version>10.2.0.3.0</version>
</dependency>
错误代码始终为XML-20221,但原因可能有所不同,例如:
The error code is consistently XML-20221, though the cause can vary, eg:
XML-20221: (Fatal Error) Invalid char in text.
XML-20100: (Fatal Error) Expected '?>'.]
XML-20121: (Fatal Error) End tag does not match start tag 'TotalDepositReqd'.
堆栈跟踪的其余部分也有所不同,但通常如下所示:
The rest of the stack trace also varies, but typically looks like:
at oracle.xml.parser.v2.XMLError.flushErrorHandler(XMLError.java:415)
at oracle.xml.parser.v2.XMLError.flushErrors1(XMLError.java:284)
at oracle.xml.parser.v2.NonValidatingParser.parseEndTag(NonValidatingParser.java:1359)
at oracle.xml.parser.v2.NonValidatingParser.parseElement(NonValidatingParser.java:1304)
at oracle.xml.parser.v2.NonValidatingParser.parseRootElement(NonValidatingParser.java:326)
at oracle.xml.parser.v2.NonValidatingParser.parseDocument(NonValidatingParser.java:293)
at oracle.xml.parser.v2.XMLParser.parse(XMLParser.java:209)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:211)
我们的Java版本是:
Our Java version is:
java version "1.6.0_16"
Java(TM) SE Runtime Environment (build 1.6.0_16-b01)
Java HotSpot(TM) Server VM (build 14.2-b01, mixed mode)
我们当前的命令行是:
java
-server
-Xmx2048m
-Xms2048m
-XX:MaxPermSize=128m
-XX:+UseConcMarkSweepGC
-Dsun.rmi.dgc.server.gcInterval=0x2932E00
-Dsun.rmi.dgc.client.gcInterval=3600000
-verbosegc
-Xloggc:/path/to/file
-gc.log
-XX:+PrintGCDetails
-XX:+PrintGCDateStamps
-Djavax.xml.transform.TransformerFactory=org.apache.xalan.processor.TransformerFactoryImpl
-Djavax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl
-Djava.endorsed.dirs=/path/to/endorsed
-Duser.country=GB
-Duser.language=en
-Dhttp.keepAlive=false foo.ListenerServer
通常情况下,我们会在几秒钟的小爆发中看到这些,这表明某些内部缓冲区已经腐败? JVM的使用时间越长,这些异常就越常见。 JVM的反弹可以解决这个问题好几天。
Typically we see these in small bursts that span a couple of seconds, which suggests to me that some internal buffer has become corrupted? These exceptions become more common the longer the JVM is up for. A bounce of the JVM resolves the issue for several days.
- 还有其他人看过类似的东西吗?
- 或许我们应该转向另一个JAXB / JAXP实现?
<如果是这样,你有没有设法解决这个问题?
推荐答案
当开发人员缓存 Unmarshaller
时,我看到过类似的问题(解组时出现零星的异常)实例并在不同的线程之间共享它。根据文档, Unmarshaller
不是线程安全的。
I've seen similar problems (sporadic exceptions during unmarshalling) when a developer cached Unmarshaller
instance and shared it between different threads. According to the documentation the Unmarshaller
is not thread safe.
这篇关于SAXParseException XML-20221文本中的char无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!