[ https://issues.apache.org/jira/browse/XMLSCHEMA-64?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17676348#comment-17676348 ]
Oscar Westra van Holthe - Kind edited comment on XMLSCHEMA-64 at 1/12/23 9:32 PM: ---------------------------------------------------------------------------------- Added PR #3 ([https://github.com/apache/ws-xmlschema/pull/3)] to fix this bug. was (Author: opwvhk): Added PR #1 ([https://github.com/apache/ws-xmlschema/pull/3)] to fix this bug. > Schema walker thinks an element was previously visited when it's not > -------------------------------------------------------------------- > > Key: XMLSCHEMA-64 > URL: https://issues.apache.org/jira/browse/XMLSCHEMA-64 > Project: XmlSchema > Issue Type: Bug > Reporter: Oscar Westra van Holthe - Kind > Priority: Major > > Consider this schema: > {code:xml} > <?xml version="1.0" encoding="UTF-8"?> > <xs:schema targetNamespace="https://www.github.com/opwvhk/schemawalkerbug" > xmlns="https://www.github.com/opwvhk/schemawalkerbug" > xmlns:xs="http://www.w3.org/2001/XMLSchema" > elementFormDefault="qualified"> > <xs:element name="RepeatedSubElementNames"> > <xs:complexType> > <xs:sequence> > <xs:element name="wrappedStringArray"> > <xs:complexType> > <xs:sequence> > <xs:element name="array" minOccurs="0" > maxOccurs="unbounded"> > <xs:complexType> > <xs:sequence> > <xs:element ref="string"/> > </xs:sequence> > </xs:complexType> > </xs:element> > </xs:sequence> > </xs:complexType> > </xs:element> > <xs:element name="wrappedNumber"> > <xs:complexType> > <xs:sequence> > <xs:element name="array" minOccurs="0" > maxOccurs="unbounded"> > <xs:complexType> > <xs:sequence> > <xs:element ref="number"/> > </xs:sequence> > </xs:complexType> > </xs:element> > </xs:sequence> > </xs:complexType> > </xs:element> > </xs:sequence> > </xs:complexType> > </xs:element> > <xs:element name="string"> > <xs:complexType> > <xs:simpleContent> > <xs:extension base="xs:string"/> > </xs:simpleContent> > </xs:complexType> > </xs:element> > <xs:element name="number"> > <xs:complexType> > <xs:simpleContent> > <xs:extension base="xs:int"/> > </xs:simpleContent> > </xs:complexType> > </xs:element> > </xs:schema> > {code} > When walking this schema, the 2nd {{array}} element is not traversed, > resulting in missing the subelements {{{}number{}}}. > > To fix, in line 241 of {{{}XmlSchemaWalker.java{}}}, only add elements to > {{visitedElements}} if they're top-level elements, or if their type is a > top-level type. > After all, infinite recursion is only possible using references, and only > toplevel elements/types can be referenced. > > So change this: > {code:java} > if (!element.isAnonymous() && !previouslyVisited) { > visitedElements.add(element.getQName()); > } {code} > Into this: > {code:java} > if (!element.isAnonymous() && !previouslyVisited && (element.isTopLevel() || > schemaType.isTopLevel()) { > visitedElements.add(element.getQName()); > } {code} -- This message was sent by Atlassian Jira (v8.20.10#820010) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@ws.apache.org For additional commands, e-mail: dev-h...@ws.apache.org