Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
fugerit79 opened this issue Mar 7, 2024 · 4 comments

Comments

@fugerit79
Copy link
Contributor

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() );
            }
        }
@fugerit79 fugerit79 changed the title 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 java.lang.ClassCastException on XsdAttribute:198 - xsd parser version 1.2.9 Mar 7, 2024
fugerit79 added a commit to fugerit79/XsdParser that referenced this issue Mar 7, 2024
fugerit79 added a commit to fugerit79/XsdParser that referenced this issue Mar 7, 2024
Possible solution for issue :
xmlet#63

This fix does not address the behaviour change in patch 1.2.9, it just try to check type before casting to insure the operation is allowed.
@lcduarte
Copy link
Member

lcduarte commented Mar 7, 2024

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
Copy link
Contributor Author

Perfect.
Thanks again for your quick feedback

@lcduarte
Copy link
Member

lcduarte commented Mar 8, 2024

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.

@lcduarte lcduarte closed this as completed Mar 8, 2024
@fugerit79
Copy link
Contributor Author

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 :
fugerit-org/fj-doc@7b88df7
Have a great time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants