[ https://issues.apache.org/jira/browse/XMLSCHEMA-56?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Colm O hEigeartaigh updated XMLSCHEMA-56: ----------------------------------------- Fix Version/s: 2.2.5 > Element defined in a base type sometimes isn't visited by an > XmlSchemaWalker's visitor > -------------------------------------------------------------------------------------- > > Key: XMLSCHEMA-56 > URL: https://issues.apache.org/jira/browse/XMLSCHEMA-56 > Project: XmlSchema > Issue Type: Bug > Affects Versions: 2.2.3, 2.2.4 > Environment: openSUSE Leap 15 > open-jdk 11 (but I've tried 1.8 and same thing happens) > xmlschema 2.2.3 and 2.2.4 (core and walker) > Reporter: Kevin > Priority: Major > Fix For: 2.2.5 > > Attachments: walk2.tar > > > EDIT 9 May 2019: I have found the source of this bug. It is in the > org.apache.ws.commons.schema.walker package. Here, both the XmlSchemaWalker > and XmlSchemaScope classes use HashMaps to store XmlSchemas indexed by > namespace. For example, in the XmlSchemaWalker's first constructor, each > schema in the given XmlSchemaCollection (the argument) is added to > schemasByNamespace (the HashMap). The problem is that if two or more xsd > files have schemas with the same target namespace (which is legal, and indeed > useful), and they are in the schema collection (e.g. one file is included by > another using <xs:include>), each call to schemasByNamespace.put(namespace, > schema) will overwrite the previously put schema for that namespace. Then, > for example, when XmlSchemaScope looks up a schema by namespace and calls > schema.getTypeByName(...) around line 326 that type will not be found unless > it was defined in the last schema for that namespace to be stored in the Map. > This results in the behaviour I reported, where an element in a base type > (i.e. one which was extended using <xs:extension>) was not visited by the > walker: the base type was not found because a schema with the same target > namespace defined in an included xsd file was found in the map instead of the > one defining the type. > One way to remedy this is for the schemasByNamespace member variables in both > XmlSchemaWalker and XmlSchemaScope to store a list of schemas for each > namespace, i.e. be a Map<String, List<XmlSchema>> rather than a Map<String, > XmlSchema>. Then, whenever looking up, for example, a type defined in a > schema with a certain namespace, access the list of XmlSchemas using > schemasByNamespace.get(namespace), and then iterate through the list of > schemas calling getTypeByName(...) until the type in question is found. > --- original bug report: > (EDIT: I have attached a new version of the project (walk2.tar) which takes > the path to the xsd files as a command line argument. It should now be > possible to use the .class files without recompiling.) > Hi, > I have a strange issue where the element in a base type (i.e. one which is > extended by another type) is not visited by the xmlschema-walker. It is > strange because it only happens in some instances of the test project (i.e. > when I copy all project files to a new directory it will sometimes happen in > that directory and sometimes not!). I cannot for the life of me discern a > pattern. > This occurs with both 2.2.3 and 2.2.4 of xmlschema (core and walker). I am on > openSUSE Leap 15 and openjdk 11 (but I've tried 1.8 and same thing happens). > Please see my attached tar file. There are two xsd files in the "xsd" > directory. The first is "test.xsd". It defines a type "Test" which extends > the type "Base". The type "Base" has an element "baseElement". The "test.xsd" > file also includes another xsd file "unused.xsd" which is empty, but the > behaviour also occurred when "unused.xsd" defined a used type, I just > simplified that part away for this test. My java file "Main.java" creates an > "XmlSchemaWalker" with a visitor "MyVisitor". "MyVisitor" prints the element > name when it visits an element. The file "myOutput" shows what happens when I > compile and run the test. > *The bug I'm seeing* is that "baseElement" is not visited by the visitor in > some instances of the project. The root element ("test") is visited. If > "baseElement" is visited when you test the project, please create a few > directories, copy the project files into each, and see if you can reproduce > the error (this is what I mean by "instances" of the project). *NOTE:* you > must provide as an argument to the program the full path to the xsd files > which are in the "xsd" subdirectory of the project. You'll also need > xmlschema-core and xmlschema-walker jar files on the classpath. > I hope you can reproduce the bug. Please let me know if you need more info. > cheers, > Kevin. > -- This message was sent by Atlassian JIRA (v7.6.3#76005) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@ws.apache.org For additional commands, e-mail: dev-h...@ws.apache.org