I am working on DAFFODIL-2377: Abort instead of diagnostic message. 
(https://issues.apache.org/jira/browse/DAFFODIL-2377)

The attached files can be used to illustrate the bug.


daffodil parse -s s2377.xsd -o d2377.xml d2377.bin

daffodil unparse -s s2377.xsd d2377.xml

Unparsing results in the below error:

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!   An unexpected exception occurred. This is a bug!   !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

The schema has three elements. The first element has a length of 1 byte and 
alignment of 1 byte while the next two elements have length = 1 and alignment = 
2. The unparser is unparsing the first element correctly but throwing the above 
exception while determining the second element. Specifically it is failing 
figuring out the fill byte to be used.

The unparser is failing on the highlighted line in ProcessorStateBase.scala in 
daffodil-runtime1:

final def fillByte: Byte = {
  if (maybeCachedFillByte.isEmpty)
    maybeCachedFillByte = 
MaybeInt(termRuntimeData.maybeFillByteEv.get.evaluate(this).toInt)
  maybeCachedFillByte.get.toByte
}

Seems like the processor state in termRuntimeData does not have the fill byte 
value from the schema. If I update the above fillByte to return a hard coded 
byte value, unparse is working fine.

I'd appreciate any pointers on how to proceed from here.


Regards,

   Shashi Ramaka
   sram...@owlcyberdefense.com<mailto:sram...@owlcyberdefense.com>
   Tel: 703-965-3656

Attachment: d2377.xml
Description: d2377.xml

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
     xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/";
     xmlns:fn="http://www.w3.org/2005/xpath-functions";
     elementFormDefault="qualified">
     
     <xs:annotation>
         <xs:appinfo source="http://www.ogf.org/dfdl/";>
             <dfdl:format
                 textBidi="no"
                 floating="no"
                 encodingErrorPolicy="replace"
                 leadingSkip="0" 
                 alignmentUnits="bytes"
                 alignment="1" 
                 trailingSkip="0"
                 textPadKind="none"
                 escapeSchemeRef=""
                 truncateSpecifiedLengthString="no"
                 textTrimKind="none" 
                 binaryNumberRep="binary"
                 
                 representation="binary"
                 byteOrder="littleEndian"
                 encoding="ISO-8859-1"
                 sequenceKind="ordered"
                 initiator=""
                 terminator=""
                 separator=""
                 ignoreCase = "yes"
                 initiatedContent="no"
                 
             />
         </xs:appinfo>
     </xs:annotation>
     
     <xs:element name="input"
         dfdl:lengthKind="implicit"
         dfdl:lengthUnits="bytes"
         >
         <xs:complexType>
             <xs:sequence dfdl:fillByte="%NUL;">
                    <xs:element name="A" type="xs:unsignedInt" 
                     dfdl:lengthKind="explicit"
                     dfdl:length="1"
                     dfdl:lengthUnits="bytes"
                     dfdl:alignment="1"
                     dfdl:alignmentUnits="bytes"
                 />
                 <xs:element name="B" type="xs:unsignedInt" 
                     dfdl:lengthKind="explicit"
                     dfdl:length="1"
                     dfdl:lengthUnits="bytes"
                     dfdl:alignment="2"
                     dfdl:alignmentUnits="bytes"
                 />
                 <xs:element name="C" type="xs:unsignedInt" 
                     dfdl:lengthKind="explicit"
                     dfdl:length="1"
                     dfdl:lengthUnits="bytes"
                     dfdl:alignment="2"
                     dfdl:alignmentUnits="bytes"
                 />
             </xs:sequence>
         </xs:complexType>
     </xs:element>
     
 </xs:schema>

Reply via email to