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

error with xsd: import using subdirectories in schemaLocation #28

Closed
hein4daddel opened this issue Sep 10, 2020 · 1 comment
Closed

Comments

@hein4daddel
Copy link

hein4daddel commented Sep 10, 2020

Hello,
first thanks for the very fast response on issue #24! Everything s fine, just left a star.
But I found another problem while parsing a xsd with subdirectories: I attached a example zip to reproduce the problem.
issue28_xsd.zip
Parsing the issue_28.xsd shows a

java.lang.NullPointerException
	at org.xmlet.xsdparser.core.XsdParserCore.lambda$null$7(XsdParserCore.java:144)
	at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
	at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
	at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382)
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
	at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
	at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:485)
	at org.xmlet.xsdparser.core.XsdParserCore.lambda$resolveOtherNamespaceRefs$8(XsdParserCore.java:123)
	at java.util.HashMap$KeySet.forEach(HashMap.java:933)

using 1.0.33-SNAPSHOT.
The problem is the import of issue_28b.xsd from issue_28.xsd (with subdirectory issue_28) and from issue_28a.xsd (without subdirectory). If the schemaLocation is specified with an absolute file, it's working.
I looked in the source code and found

    private Map<String, List<ReferenceBase>> parseElements = new HashMap<>();
    private Map<String, List<UnsolvedReference>> unsolvedElements = new HashMap<>();
    List<String> schemaLocations = new ArrayList<>();
    Map<String, String> schemaLocationsMap = new HashMap<>();
    protected String currentFile;

After debugging I saw, thew the keys in schemaLocations sometimes have the directory in it, sometimes not. So I'd suggest using URI instead:

    private Map<URL, List<ReferenceBase>> parseElements = new HashMap<>();
    private Map<URL, List<UnsolvedReference>> unsolvedElements = new HashMap<>();
    List<URL> schemaLocations = new ArrayList<>();
    protected URL currentFile;

because the URLs are normalized. (The schemaLocationsMap not necessary an more). Instead of string manipulation to create a new filename, using
url = new URL(currentFile, importedFileName);
is easier.

If I can help you with more explanations or java code, please let me know.

@lcduarte
Copy link
Member

Hello,

Thanks for the star! Also sorry for taking so long this time around.

I probably need to improve the way I work with files, but for now I solved your issue with a temporary solution. I tested with your use case and it didn't give me any errors parsing. A new release is available, (1.1.0), with the fix.

I'll try to improve XsdParser with your suggestion once I have some more free time. Or if you are up to it you can create a pull request with your solution and I'll give it a look. Either way, thanks for the feedback!

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