[ 
https://issues.apache.org/jira/browse/DAFFODIL-2879?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17821414#comment-17821414
 ] 

Steve Lawrence commented on DAFFODIL-2879:
------------------------------------------

I think the issue here is that at one point optionals were implemented as 
arrays that could only have a max length of one. I'm not sure when that 
changed, but I don't think that is the case anymore. As far as the infoset is 
concerned, optionals are the same as scalars that just might not exist.

So I think this ambiguity check might be incorrect:

https://github.com/apache/daffodil/blob/main/daffodil-core/src/main/scala/org/apache/daffodil/core/dpath/Expression.scala#L981-L987

A path step can never ambiguously reference an array or optional, because in 
the infoset they are not the same--one is a DIArray and the other is a 
DIElement. If anything, we can only allow an ambiguous reference to a scalar or 
an optional, since they are both DIElements. And if a step could be an optional 
or a scalar, there's just a possibility that the optional might not exist and 
create a processing error.

Though, I though we had an issue where optionals required a predicate? So maybe 
scalars and optionals can't be allowed either? So maybe a path step can never 
be ambiguous? It must reference either an array, optional or scala?

> Group evaluation throwing ClassCastException for optional element
> -----------------------------------------------------------------
>
>                 Key: DAFFODIL-2879
>                 URL: https://issues.apache.org/jira/browse/DAFFODIL-2879
>             Project: Daffodil
>          Issue Type: Bug
>          Components: Back End
>    Affects Versions: 3.6.0
>            Reporter: Peter Katlic
>            Priority: Major
>
> 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:
> {code:java}
> <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>{code}
> Sequence schema:
> {code:java}
> <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>{code}
> Uncommenting 
> {code:java}
> <xs:group ref="countGroup"/>{code}
>  and commenting out 
> {code:java}
> <xs:element name="count" type="xs:int" dfdl:representation="binary" 
> dfdl:inputValueCalc="{ fn:count(../ex:foo) }"/>{code}
>  will produce the following error:
> {code:java}
> java.lang.ClassCastException: class 
> org.apache.daffodil.runtime1.infoset.DISimple cannot be cast to class 
> org.apache.daffodil.runtime1.infoset.DIArray{code}
> It seems as if the optional is evaluated as a DownArray instead of a 
> DownElement.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to