Mike Beckerle created DAFFODIL-2297:
---------------------------------------

             Summary: Runtime SDE - zero-length integer gets no value. Value 
should probably be 0, or it should be a parse error
                 Key: DAFFODIL-2297
                 URL: https://issues.apache.org/jira/browse/DAFFODIL-2297
             Project: Daffodil
          Issue Type: Bug
          Components: Back End
    Affects Versions: 2.5.0
            Reporter: Mike Beckerle
             Fix For: 2.6.0


I have a schema which has a padding field that can have between 0 and 5 bits in 
it.

The number of padding bits is controlled by an external variable which defaults 
to 2.

If I set it to 0 bits, I get an error:
{code:java}
Runtime Schema Definition Error: Expression Evaluation Error: Element {}spare 
does not have a value.{code}
That comes from this definition:
{code:java}
<xs:element name="spare" type="vmfgi:padding" dfdl:length="{ 
$l16common:l16WordPaddingBits }"/>{code}
The type vmfgi:padding has an assert that checks that the padding field 
contains the value 0.

 
{code:java}
<xs:simpleType name="padding" dfdl:lengthKind="explicit">
  <xs:annotation>
   <xs:appinfo source="http://www.ogf.org/dfdl/";>
     <dfdl:assert test="{ . eq 0 }" />
   </xs:appinfo>
  </xs:annotation>
 <xs:restriction base="xs:unsignedInt">
   <xs:enumeration value="0" />
 </xs:restriction>
</xs:simpleType>{code}
Arguably, there shouldn't be an assert here. Just the restriction that it is 0 
valued.

But ignoring that for a minute. If I did need this padding element to have a 
value, it will get a value if there are any bits parsed, but it has no value at 
all if the length is zero bits.

That requires me to model these spare fields as a complex type so that I can 
have a choice between no spare field, and having one, based on the padding bits 
value being 0 or greater than zero.

I could do that. But arguably, a zero-bit-long integer should have value 0 
shouldn't it? That certainly would simplify things.

I have requested a clarification from the DFDL Workgroup. However, a runtime 
SDE for this clearly seems wrong. The failure should be either a parse error 
because zero bits is not a legal representation, or there should be no error 
and the integer value should be 0.

 

 

 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to