Description
A group is defined with an element using fn:count and referenced inside a sequence of array and optional elements. See the test count_21b in daffodil-test/src/test/resources/org/apache/daffodil/section23/dfdl_functions/Functions.tdml for an example.
Group schema:
<xs:group name="countGroup"> <xs:sequence> <xs:element name="count" type="xs:int" dfdl:representation="binary" dfdl:inputValueCalc="{ fn:count(../ex:foo) }"/> </xs:sequence> </xs:group>
Sequence schema:
<xs:element name="arrayOptional"> <xs:complexType> <xs:sequence> <xs:element name="array"> <xs:complexType> <xs:sequence> <xs:element name="foo" type="xs:int" minOccurs="2" maxOccurs="2" dfdl:representation="binary"/> <xs:group ref="countGroup"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="optional"> <xs:complexType> <xs:sequence> <xs:element name="foo" type="xs:int" minOccurs="0" maxOccurs="1" dfdl:representation="binary"/> <!-- throws ClassCastException, possible bug in Daffodil group evaluation --> <!-- <xs:group ref="countGroup"/> --> <xs:element name="count" type="xs:int" dfdl:representation="binary" dfdl:inputValueCalc="{ fn:count(../ex:foo) }"/> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element>
Uncommenting
<xs:group ref="countGroup"/>
and commenting out
<xs:element name="count" type="xs:int" dfdl:representation="binary" dfdl:inputValueCalc="{ fn:count(../ex:foo) }"/>
will produce the following error:
java.lang.ClassCastException: class org.apache.daffodil.runtime1.infoset.DISimple cannot be cast to class org.apache.daffodil.runtime1.infoset.DIArray
It seems as if the optional is evaluated as a DownArray instead of a DownElement.