Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SAXParseException XML-20221 Invalid char in text

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.]

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>

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)

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)

Our current command line is:

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

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.

  • Has anyone else seen something similar?
  • If so, did you manage to to resolve this?
  • Perhaps we should we move to a different JAXB/JAXP implementation?
like image 841
toolkit Avatar asked Oct 08 '22 15:10

toolkit


1 Answers

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.

like image 169
kan Avatar answered Oct 10 '22 08:10

kan