EXIficient / exificient-grammars

Java Implementation of EXI (grammars part)
http://exificient.github.io/java/
MIT License
4 stars 9 forks source link

Test for Java assertion #20

Closed guusdk closed 1 year ago

guusdk commented 1 year ago

When creating grammar from a set of XSDs provided by the XMPP Standards Foundation, com.siemens.ct.exi.grammars.EXIContentModelBuilder.handleStateEntries() throws an AssertionError (when assertions are enabled in the VM), with the latest state of the code (v1.0.4 and 1.0.5-SNAPSHOT).

This PR adds a unit test that reproduces this behavior.

The assertion that fails is: https://github.com/EXIficient/exificient-grammars/blob/77413b7978c2b6fa4a97ab0c3debb16f12d2712f/src/main/java/com/siemens/ct/exi/grammars/EXIContentModelBuilder.java#L378

The stack trace for the error is:

java.lang.AssertionError
    at com.siemens.ct.exi.grammars.EXIContentModelBuilder.handleStateEntries(EXIContentModelBuilder.java:378)
    at com.siemens.ct.exi.grammars.EXIContentModelBuilder.handleStateEntries(EXIContentModelBuilder.java:484)
    at com.siemens.ct.exi.grammars.EXIContentModelBuilder.handleStateEntries(EXIContentModelBuilder.java:484)
    at com.siemens.ct.exi.grammars.EXIContentModelBuilder.handleStateEntries(EXIContentModelBuilder.java:414)
    at com.siemens.ct.exi.grammars.EXIContentModelBuilder.handleParticle(EXIContentModelBuilder.java:342)
    at com.siemens.ct.exi.grammars.XSDGrammarsBuilder.translateComplexTypeDefinitionToFSA(XSDGrammarsBuilder.java:1687)
    at com.siemens.ct.exi.grammars.XSDGrammarsBuilder.translateTypeDefinitionToFSA(XSDGrammarsBuilder.java:1613)
    at com.siemens.ct.exi.grammars.XSDGrammarsBuilder.translatElementDeclarationToFSA(XSDGrammarsBuilder.java:1472)
    at com.siemens.ct.exi.grammars.XSDGrammarsBuilder.toGrammars(XSDGrammarsBuilder.java:993)
    at com.siemens.ct.exi.grammars.GrammarFactory.createGrammars(GrammarFactory.java:91)
    at com.siemens.ct.exi.grammars.GrammarXSFTest.testAssertionNotThrown(GrammarXSFTest.java:49)
    <28 internal lines>

I am unsure if this is a problem in Exificient, the XSDs that are used, or the test setup. However, I am unable to progress further on this issue, and am looking for feedback from more capable eyes.

danielpeintner commented 1 year ago

Hi @guusdk

I looked at your schemas and they seem to contain issues as far as I can tell. I used Oxygen to validate them but other IDEs or Xerces library might report the same issues (see below, where it mentions also the lines)

I assume that's why processing the schemas fails.

Error1

System-ID: ...\resources\xsf\streams.xsd Haupt-Validierungsdatei: ...\resources\xsf\defaultSchema.xsd Programmname: Xerces Fehlerlevel: error Beschreibung: cos-nonambig: "jabber:server":iq and WC[##other:"http://etherx.jabber.org/streams",""] (or elements from their substitution group) violate "Unique Particle Attribution". During validation against this schema, ambiguity would be created for those two particles. Start: 24:6 End: 24:20 URL: http://www.w3.org/TR/xmlschema-1/#cos-nonambig

Error2

System-ID: ...\resources\xsf\streams.xsd Haupt-Validierungsdatei: ...\resources\xsf\defaultSchema.xsd Programmname: Xerces Fehlerlevel: error Beschreibung: cos-nonambig: "urn:ietf:params:xml:ns:xmpp-streams":text and WC[##other:"http://etherx.jabber.org/streams",""] (or elements from their substitution group) violate "Unique Particle Attribution". During validation against this schema, ambiguity would be created for those two particles. Start: 75:6 End: 75:20 URL: http://www.w3.org/TR/xmlschema-1/#cos-nonambig

guusdk commented 1 year ago

Thank you for your fast response. You are correct. Apparently, this problem in the schema was identified long ago: https://xmpp.org/extensions/xep-0322.html#patch

With the patch from that text applied, the assertion is no longer triggered.