You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ws.apache.org by "Oscar Westra van Holthe - Kind (Jira)" <ji...@apache.org> on 2023/01/12 21:25:00 UTC
[jira] [Created] (XMLSCHEMA-64) Schema walker thinks an element was previously visited when it's not
Oscar Westra van Holthe - Kind created XMLSCHEMA-64:
-------------------------------------------------------
Summary: 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
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-unsubscribe@ws.apache.org
For additional commands, e-mail: dev-help@ws.apache.org