I use Saxon EE APIs to validate XML payload with XSDs. My environment is OSGi.
For a particular XSD, I'm facing a weird error.
java.lang.NoClassDefFoundError: com/saxonica/ee/bytecode/simtype/AtomicTypeValidator
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:858)
at java.lang.ClassLoader.defineClass(ClassLoader.java:704)
at net.sf.saxon.java.JavaPlatform$MyClassLoader.registerClass(JavaPlatform.java:441)
at com.saxonica.ee.bytecode.util.CompilerService.makeClass(CompilerService.java:1067)
at com.saxonica.ee.bytecode.util.CompilerService.compileAtomicValidator(CompilerService.java:1241)
at com.saxonica.ee.schema.UserAtomicType.validateContent(UserAtomicType.java:373)
at com.saxonica.ee.validate.SimpleContentValidator.endElement(SimpleContentValidator.java:239)
at com.saxonica.ee.validate.ValidationStack.endElement(ValidationStack.java:412)
at net.sf.saxon.event.ProxyReceiver.endElement(ProxyReceiver.java:182)
at net.sf.saxon.event.StartTagBuffer.endElement(StartTagBuffer.java:290)
at com.saxonica.ee.validate.StartTagBufferEE.endElement(StartTagBufferEE.java:58)
at net.sf.saxon.event.PathMaintainer.endElement(PathMaintainer.java:62)
at net.sf.saxon.event.DocumentValidator.endElement(DocumentValidator.java:68)
at net.sf.saxon.event.ReceivingContentHandler.endElement(ReceivingContentHandler.java:459)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:609)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1782)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2967)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:602)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:112)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:505)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:842)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:771)
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:643)
at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:427)
at net.sf.saxon.event.Sender.send(Sender.java:164)
at com.saxonica.ee.s9api.SchemaValidatorImpl.validate(SchemaValidatorImpl.java:587)
Observation: The scenario with same XSD and payload works fine if we restrict the payload size i.e. in this number of xml elements; if we reduce to less than 80 elements, it works and more than 80 elements we get following error.
Any help?
We have had a couple of similar problems involving Saxon bytecode generation in environments using OSGi, see
https://saxonica.plan.io/issues/4036
https://saxonica.plan.io/issues/3814
The users in those cases were able to get around the problem by setting a different classloader on the Saxon Configuration.
I have been a bit reluctant to change the product code in this area because it is very difficult to test. The environments that use custom class-loading (such as Websphere and Eclipse) tend to be things we don't have installed "in the lab", which makes it difficult to be sure that any changes we make don't cause other workloads to fail.
The reason the problem only kicks in when the file reaches a certain size is that bytecode generation only takes place for code fragments that have been executed a certain number of times, to ensure that the cost of generating the code is not incurred where it brings no benefit. (In this case, with schema validation, the bytecode is performing validation against particular user-defined XSD simple types).
You can, of course, disable bytecode generation entirely with an appropriate setting on the Configuration.