entur / schema2proto

XSD to proto descriptor conversion tool capable of manipulating proto files as well
European Union Public License 1.2
37 stars 20 forks source link

Crash during conversion of AIXM #102

Open pyssling opened 3 years ago

pyssling commented 3 years ago

Hi,

I previously used xsd2thrift for converting XSDs but decided it's time to move to schema2proto . I'm working with large complicated XSDs generated by Sparx Systems Enterprise Architect - in this case the AIXM for aeronautical data - the XSDs are available here:

http://aixm.aero/document/aixm-511-xml-schema-xsd

I'm using the one with local copies of all dependencies. I can convert some of the dependencies - but once I start with the larger ones things crash pretty immediately on the following exception:

[main] INFO no.entur.schema2proto.generateproto.Schema2Proto - Starting to parse aixm-5.1.1/AIXM_DataTypes.xsd
[main] ERROR no.entur.schema2proto.generateproto.Schema2Proto - Error processing proto files: null
java.lang.NullPointerException
        at no.entur.schema2proto.generateproto.SchemaParser.navigateSubTypes(SchemaParser.java:388)
        at no.entur.schema2proto.generateproto.SchemaParser.processGroupAsSequence(SchemaParser.java:993)
        at no.entur.schema2proto.generateproto.SchemaParser.processGroup(SchemaParser.java:922)
        at no.entur.schema2proto.generateproto.SchemaParser.processComplexType(SchemaParser.java:696)
        at no.entur.schema2proto.generateproto.SchemaParser.lambda$processSchemaSet$2(SchemaParser.java:191)
        at java.base/java.util.TreeMap.forEach(TreeMap.java:1002)
        at no.entur.schema2proto.generateproto.SchemaParser.processSchemaSet(SchemaParser.java:191)
        at no.entur.schema2proto.generateproto.SchemaParser.parse(SchemaParser.java:137)
        at no.entur.schema2proto.generateproto.Schema2Proto.parseAndSerialize(Schema2Proto.java:107)
        at no.entur.schema2proto.generateproto.Schema2Proto.<init>(Schema2Proto.java:92)
        at no.entur.schema2proto.generateproto.Schema2Proto.main(Schema2Proto.java:125)

All help much appreciated!

pyssling commented 3 years ago

Ok - spent some time debugging this - it appears that at

        at no.entur.schema2proto.generateproto.SchemaParser.navigateSubTypes(SchemaParser.java:388)

I have a substitutable of type ListSimpleTypeImpl which extends SimpleTypeImpl which when the method asComplexType() is called returns a null - which when isAbstract() is called throws the NullPointerException . I guess there should be a check on whether asComplexType() returns null.

pyssling commented 3 years ago

I patched over this bug - but not necessarily in a good way - and quickly hit upon a few more bugs. If someone who is familiar with how this works has time to download these schemas and fix enough bugs/missing features to get this working that would be very much appreciated. I've looked at the source code - but I'm afraid it's quite a starting stretch to get into this.

pyssling commented 3 years ago

@seime Thanks for the help.

I'm getting a lot further now, here are the options I'm passing in:

--outputDirectory out aixm-5.1.1/AIXM_Features.xsd

Then it crashes on:

Exception in thread "main" java.lang.StackOverflowError
    at java.base/java.util.HashMap.hash(HashMap.java:339)
    at java.base/java.util.HashMap.get(HashMap.java:552)
    at no.entur.schema2proto.generateproto.ProtoSerializer.hasRecursiveImports(ProtoSerializer.java:720)
    at no.entur.schema2proto.generateproto.ProtoSerializer.hasRecursiveImports(ProtoSerializer.java:725)
    at no.entur.schema2proto.generateproto.ProtoSerializer.hasRecursiveImports(ProtoSerializer.java:725)
    at no.entur.schema2proto.generateproto.ProtoSerializer.hasRecursiveImports(ProtoSerializer.java:725)
    at no.entur.schema2proto.generateproto.ProtoSerializer.hasRecursiveImports(ProtoSerializer.java:725)
....

So endless recursion it seems.

I also get one warning which I think is just bad schema design:

[main] WARN no.entur.schema2proto.generateproto.ProtoSerializer - Cannot uppercase message secondDefiningParameterType to SecondDefiningParameterType as type already exist! Renaming ignored

I think this is something I can patch around in the original schema.

Stort tack!

salimfadhleyhtp commented 3 years ago

I'm seeing a similar error:

java -jar /tmp/schema2proto/schema2proto-lib/target/schema2proto-lib-1.40-SNAPSHOT.jar  "/xsds/BOALF_DataPush_Response_XSD.xsd" --outputDirectory="/proto"
[main] INFO no.entur.schema2proto.generateproto.Schema2Proto - Starting to parse /xsds/BOALF_DataPush_Response_XSD.xsd
[main] INFO no.entur.schema2proto.generateproto.ProtoSerializer - Writing proto files to /proto
[main] ERROR no.entur.schema2proto.generateproto.Schema2Proto - Error processing proto files: null
java.lang.NullPointerException
        at no.entur.schema2proto.generateproto.ProtoSerializer.lambda$moveReusedLocalTypesToGlobal$32(ProtoSerializer.java:1252)
        at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:176)
        at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1655)
        at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
        at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
        at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)
        at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
        at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578)
        at no.entur.schema2proto.generateproto.ProtoSerializer.moveReusedLocalTypesToGlobal(ProtoSerializer.java:1252)
        at no.entur.schema2proto.generateproto.ProtoSerializer.serialize(ProtoSerializer.java:137)
        at no.entur.schema2proto.generateproto.Schema2Proto.parseAndSerialize(Schema2Proto.java:114)
        at no.entur.schema2proto.generateproto.Schema2Proto.<init>(Schema2Proto.java:94)
        at no.entur.schema2proto.generateproto.Schema2Proto.main(Schema2Proto.java:127)

This is one of the XSDs I am trying to convert:

https://gist.github.com/salimfadhleyhtp/30fe50025f439637a05f979da39df004

salimfadhleyhtp commented 3 years ago

@pyssling I think this error is caused when the targetNamespace field is not set.