Uploaded image for project: 'Daffodil'
  1. Daffodil
  2. DAFFODIL-2354

newVariableInstance leads to mark state exception

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 2.6.0
    • 3.0.0
    • Back End
    • None

    Description

      The following schema uses newVariableInstance with the goal of parameterizing repeated types. Note that this snippet does not even use the type and count variables, or parameterizes anything, which is the intention. The ultimate goal is to have set the type and count variables based on the type/count elements, and then use those variables in the choice rather than using XPath to access the elements. Things were simplified to create the smallest test case.

      <?xml version="1.0" encoding="UTF-8"?> 
      
      <xs:schema
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/">
      
        <xs:include schemaLocation="org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd" />
      
        <xs:annotation>
          <xs:appinfo source="http://www.ogf.org/dfdl/">
            <dfdl:format ref="GeneralFormat" />
            <dfdl:defineVariable name="type" type="xs:int" />
            <dfdl:defineVariable name="count" type="xs:int" />
          </xs:appinfo>
        </xs:annotation>
      
        <xs:element name="file">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="records" maxOccurs="unbounded" dfdl:terminator="%NL;">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="type" type="xs:int" dfdl:lengthKind="explicit" dfdl:length="1" />
                    <xs:element name="count" type="xs:int" dfdl:lengthKind="explicit" dfdl:length="1" />
                    <xs:sequence>
                      <xs:annotation>
                        <xs:appinfo source="http://www.ogf.org/dfdl/">
                          <dfdl:newVariableInstance ref="type" />
                          <dfdl:newVariableInstance ref="count" />
                        </xs:appinfo>
                      </xs:annotation>
                      <xs:sequence>
                        <xs:choice dfdl:choiceDispatchKey="{ xs:string(./type) }">
                          <xs:element name="int" type="xs:int" dfdl:choiceBranchKey="1" maxOccurs="unbounded"
                            dfdl:occursCountKind="expression" dfdl:occursCount="{ ../count }"
                            dfdl:lengthKind="explicit" dfdl:length="1" />
                          <xs:element name="str" type="xs:string" dfdl:choiceBranchKey="2" maxOccurs="unbounded"
                            dfdl:occursCountKind="expression" dfdl:occursCount="{ ../count }"
                            dfdl:lengthKind="explicit" dfdl:length="1" />
                        </xs:choice>
                      </xs:sequence>
                    </xs:sequence>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      
      

      So each line has a type (either 1 for int or 2 for string) and a count, followed by count occurrances of that type.

      This should parse data that looks something like this:

      1512345
      26abcdef
      

      However, trying to parse this data leads to a usage exception about the mark state being messed up.

      Simply removing the newVariableInstance annotation allows things to work, so somehow that is messing with state in a way that is unexpected.

      Attachments

        Activity

          People

            Unassigned Unassigned
            slawrence Steve Lawrence
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 0.5h
                0.5h