phax / maven-jaxb2-plugin

The most advanced JAXB 2.x/3.0/4.0 Maven Plugin for XML Schema compilation.
BSD 2-Clause "Simplified" License
7 stars 2 forks source link

Error while parsing bigger schemas #15

Closed razum90 closed 10 months ago

razum90 commented 1 year ago

Hi and thank you for developing this. It has unblocked us so that we can now finally update spring-boot to the latest version in our project.

There's an error I am getting when using this plugin for our bigger xsd files, saying:

[ERROR] Error while parsing schema(s).Location [ file:/Users/rasmus/Repositories/...xsd{275,79}].
org.xml.sax.SAXParseException: Current configuration of the parser doesn't allow the expansion of a content model for a complex type to contain more than 5 000 nodes.
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException (ErrorHandlerWrapper.java:204)
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError (ErrorHandlerWrapper.java:178)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError (XMLErrorReporter.java:400)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.reportSchemaErr (XSDHandler.java:4254)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.reportSchemaFatalError (XSDHandler.java:4233)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSAttributeChecker.reportSchemaFatalError (XSAttributeChecker.java:1569)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSAttributeChecker.checkAttributes (XSAttributeChecker.java:1201)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSAttributeChecker.checkAttributes (XSAttributeChecker.java:960)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDElementTraverser.traverseLocal (XSDElementTraverser.java:160)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.traverseLocalElements (XSDHandler.java:3707)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.parseSchema (XSDHandler.java:666)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadSchema (XMLSchemaLoader.java:618)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadGrammar (XMLSchemaLoader.java:577)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadGrammar (XMLSchemaLoader.java:543)
    at com.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory.newSchema (XMLSchemaFactory.java:281)
    at com.sun.tools.xjc.reader.xmlschema.parser.SchemaConstraintChecker.check (SchemaConstraintChecker.java:78)
    at org.jvnet.mjiip.v_4_0.XJC40Mojo.loadModel (XJC40Mojo.java:84)
    at org.jvnet.mjiip.v_4_0.XJC40Mojo.doExecute (XJC40Mojo.java:51)
    at org.jvnet.mjiip.v_4_0.XJC40Mojo.doExecute (XJC40Mojo.java:36)
    at org.jvnet.jaxb2.maven2.RawXJCMojo.doExecute (RawXJCMojo.java:572)
    at org.jvnet.jaxb2.maven2.RawXJCMojo.execute (RawXJCMojo.java:371)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:342)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:330)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:213)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:175)
    at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:76)
    at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:163)
    at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:160)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
    at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call (MultiThreadedBuilder.java:193)
    at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call (MultiThreadedBuilder.java:180)
    at java.util.concurrent.FutureTask.run (FutureTask.java:264)
    at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:539)
    at java.util.concurrent.FutureTask.run (FutureTask.java:264)
    at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1136)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:635)
    at java.lang.Thread.run (Thread.java:833)
[ERROR] SchemaConstraintChecker failed

I did not get this error before upgrading. However the generation seems to be working anyway, so I am confused what the implications of getting this error is for us.

Any ideas?

laurentschoelens commented 1 year ago

@razum90 seems this error is only trigger by the validation phase of xjc. It seems it doesnt handle big scheme definition (5k nodes is a big one) Could you provide more context about this one so we can test it ? Regards

razum90 commented 1 year ago

Heya @laurentschoelens, thanks for the reply. I am afraid I cannot provide the XSD file I am working with. But it is indeed very big. Should be able to reproduce it by finding some big XSD (more than 5k nodes) online, and trying with that one maybe?

laurentschoelens commented 1 year ago

Yes for sure, but will have to find one :)

By analysting the stacktrace, it seems that only validation failed :

at com.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory.newSchema (XMLSchemaFactory.java:281)`

That should explain why generation is OK and you have only this error that pops out of "nowhere"

razum90 commented 1 year ago

Yes, I guess that's the hard part 😅

Yup it is not blocking the generation. But would be nice to get rid of the error msg.

laurentschoelens commented 1 year ago

My guess is this should be configurable See https://github.com/JetBrains/jdk8u_jaxp/blob/ef214d85066b758a01f9949298b255b8ffd8ab19/src/com/sun/org/apache/xerces/internal/impl/xs/traversers/XSAttributeChecker.java#L1194

I'll try to look deeper later

laurentschoelens commented 1 year ago

@razum90 : Could you try adding following systemproperty when running your generation ?

http://www.oracle.com/xml/jaxp/properties/maxOccurLimit (deprecated since jdk17 but still observed) jdk.xml.maxOccurLimit

Defining to 0 means no limit Default is 5000

If this works, we should be able to add some property in system based on plugin parameter to parse bigger schema with "noLimit" value defined.

razum90 commented 1 year ago

Yes @laurentschoelens, it appears to be working when providing that system property 👍 getting no exceptions.

I.e. mvn clean compile ... -Djdk.xml.maxOccurLimit=99999999