xmlet / XsdParser

A Parser that parses a XSD file into a Java Structure.
MIT License
80 stars 34 forks source link

java.lang.ClassCastException on XsdAttribute:198 - xsd parser version 1.2.9 #63

Closed fugerit79 closed 8 months ago

fugerit79 commented 8 months ago

To start, thanks again for your great work with this useful parser!

Describe the bug When parsing a xsd, I get this exception :

java.lang.ClassCastException: class org.xmlet.xsdparser.xsdelements.XsdBuiltInDataType cannot be cast to class org.xmlet.xsdparser.xsdelements.XsdSimpleType (org.xmlet.xsdparser.xsdelements.XsdBuiltInDataType and org.xmlet.xsdparser.xsdelements.XsdSimpleType are in unnamed module of loader 'app')
    at org.xmlet.xsdparser.xsdelements.XsdAttribute.getXsdSimpleType(XsdAttribute.java:198) ~[xsdParser-1.2.9.jar:?]

Expected behavior Up to version 1.2.8 I was not getting the exception

Library Version 1.2.9

Additional context To reprocude the exception it is possible to use this xsd : sample xsd With this code :

        XsdParser xsdParser = new XsdParser( "./src/test/resources/docs/doc-custom.xsd" );
        List<XsdElement> elements = xsdParser.getResultXsdElements().collect(Collectors.toList());
        for (XsdElement currentElement : elements) {
            XsdComplexType complexType = currentElement.getXsdComplexType();
            if ( complexType != null ) {
                Logger.getAnonymousLogger().log(Level.INFO, "current type : "+complexType );
                // exception arises here : 
                complexType.getXsdAttributes().forEach( a -> a.getAllRestrictions() );
            }
        }
lcduarte commented 8 months ago

Hello,

Thanks for using the library, I'm glad you find it useful!

I didn't fully check the implications of my change and without tests covering this specific case it was overlooked, Your solution works, I'll probably release a new version with the fix either tomorrow or saturday.

fugerit79 commented 8 months ago

Perfect. Thanks again for your quick feedback

lcduarte commented 8 months ago

Hi,

I've applied the fix and released the version 1.2.10. I've had an issue releasing the version but it seems to be available now, let me know if you have any more issues.

fugerit79 commented 8 months ago

Hi,

I've applied the fix and released the version 1.2.10. I've had an issue releasing the version but it seems to be available now, let me know if you have any more issues.

Thanks a lot @lcduarte , already integrated the new version. It seems all the test passed this time : https://github.com/fugerit-org/fj-doc/commit/7b88df72a0aa9f2271d6eddb176a587f5ad54bda Have a great time.