JiBX
  1. JiBX
  2. JIBX-172

ArrayIndexOutOfBoundsException during marshalling a element contains large XML-data

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: JiBX 1.0.1
    • Fix Version/s: JiBX 1.1.6
    • Component/s: core
    • Labels:
      None
    • Environment:
      JDK 1.4.2_03-b02
      WinXP pro / Unix
    • Number of attachments :
      0

      Description

      An exception is thrown when marshalling an element contains a XML-String and the encoded size exceeds 4K.
      if I replace all following characters "<", ">" for example with "#", "*" the marshalling works fine.

      Example which throws Exception:
      String wert = "<imp id=\"get_current_alarms\">\n" +
      "<alarm_op_result><![CDATA[CS_ALARM_RETRIEVED]]></alarm_op_result>\n" +
      "<imp id=\"alarms\">\n" +
      "<imp id=\"alarm_message\">\n" +
      "<alarm_condition><![CDATA[CS_LOSS_OF_SYNC]]></alarm_condition>\n" +
      "<event_time><![CDATA[0]]></event_time>\n" +
      "<layer1_data><![CDATA[CS_ALM_NO_LAYER1_ADDITIONAL_DATA]]></layer1_data>\n" +
      "<sync_loss_data><![CDATA[CS_LFA_AIS_OR_LIS_AT_NT]]></sync_loss_data>\n" +
      "<bit_error_data><![CDATA[CS_BIT_ERR_DIRECTION_IN]]></bit_error_data>\n" +
      "<nrt_alm_err_mesg/>\n" +
      "<imp id=\"line\">\n" +
      "<switch_short_name><![CDATA[0000-T7---D]]></switch_short_name>\n" +
      "<equipment_number/>\n" +
      "<directory_number><![CDATA[00000000]]></directory_number>\n" +
      "<stroke_number><![CDATA[0]]></stroke_number>\n" +
      "</imp>\n" +
      "</imp>\n" +
      "<imp id=\"alarm_message\">\n" +
      "<alarm_condition><![CDATA[CS_BER_EXCEEDED_10_6]]></alarm_condition>\n" +
      "<event_time><![CDATA[0000000000]]></event_time>\n" +
      "<layer1_data><![CDATA[CS_ALM_NO_LAYER1_ADDITIONAL_DATA]]></layer1_data>\n" +
      "<sync_loss_data><![CDATA[CS_NO_SYNC_LOSS_ADDITIONAL_DATA]]></sync_loss_data>\n" +
      "<bit_error_data><![CDATA[CS_BIT_ERR_DIRECTION_IN]]></bit_error_data>\n" +
      "<nrt_alm_err_mesg/>\n" +
      "<imp id=\"line\">\n" +
      "<switch_short_name><![CDATA[0000-T7---D]]></switch_short_name>\n" +
      "<equipment_number/>\n" +
      "<directory_number><![CDATA[0000000000]]></directory_number>\n" +
      "<stroke_number><![CDATA[0]]></stroke_number>\n" +
      "</imp>\n" +
      "</imp>\n" +

      "<imp id=\"alarm_message\">\n" +
      "<alarm_condition><![CDATA[CS_LAYER2_DEACTIVATION]]></alarm_condition>\n" +
      "<event_time><![CDATA[0]]></event_time>\n" +
      "<layer1_data><![CDATA[CS_ALM_NO_LAYER1_ADDITIONAL_DATA]]></layer1_data>\n" +
      "<sync_loss_data><![CDATA[CS_NO_SYNC_LOSS_ADDITIONAL_DATA]]></sync_loss_data>\n" +
      "<bit_error_data><![CDATA[CS_BIT_ERR_DIRECTION_IN]]></bit_error_data>\n" +
      "<nrt_alm_err_mesg/>\n" +
      "<imp id=\"line\">\n" +
      "<switch_short_name><![CDATA[0000-T7---D]]></switch_short_name>\n" +
      "<equipment_number/>\n" +
      "<directory_number><![CDATA[0000000000]]></directory_number>\n" +
      "<stroke_number><![CDATA[0]]></stroke_number>\n" +
      "</imp>\n" +
      "</imp>\n" +

      "<imp id=\"alarm_message\">\n" +
      "<alarm_condition><![CDATA[CS_LAYER1_INTERRUPT]]></alarm_condition>\n" +
      "<event_time><![CDATA[0000000000]]></event_time>\n" +
      "<layer1_data><![CDATA[CS_ALM_NO_LAYER1_ADDITIONAL_DATA]]></layer1_data>\n" +
      "<sync_loss_data><![CDATA[CS_NO_SYNC_LOSS_ADDITIONAL_DATA]]></sync_loss_data>\n" +
      "<bit_error_data><![CDATA[CS_BIT_ERR_DIRECTION_IN]]></bit_error_data>\n" +
      "<nrt_alm_err_mesg/>\n" +
      "<imp id=\"line\">\n" +
      "<switch_short_name><![CDATA[0000-T7---D]]></switch_short_name>\n" +
      "<equipment_number/>\n" +
      "<directory_number><![CDATA[00000000000]]></directory_number>\n" +
      "<stroke_number><![CDATA[0]]></stroke_number>\n" +
      "</imp>\n" +
      "</imp>\n" +

      "<imp id=\"alarm_message\">\n" +
      "<alarm_condition><![CDATA[CS_TRANS_QUALITY_CAUSE_DEAC]]></alarm_condition>\n" +
      "<event_time><![CDATA[0]]></event_time>\n" +
      "<layer1_data><![CDATA[CS_ALM_NO_LAYER1_ADDITIONAL_DATA]]></layer1_data>\n" +
      "<sync_loss_data><![CDATA[CS_NO_SYNC_LOSS_ADDITIONAL_DATA]]></sync_loss_data>\n" +
      "<bit_error_data><![CDATA[CS_BIT_ERR_DIRECTION_IN]]></bit_error_data>\n" +
      "<nrt_alm_err_mesg/>\n" +
      "<imp id=\"line\">\n" +
      "<switch_short_name><![CDATA[0000000000-T7---D]]></switch_short_name>\n" +
      "<equipment_number/>\n" +
      "<directory_number><![CDATA[0000000000]]></directory_number>\n" +
      "<stroke_number><![CDATA[0]]></stroke_number>\n" +
      "</imp>\n" +
      "</imp>\n" +

      "<imp id=\"alarm_message\">\n" +
      "<alarm_condition><![CDATA[CS_POWER_FAILURE_IN_TERMINAL]]></alarm_condition>\n" +
      "<event_time><![CDATA[0]]></event_time>\n" +
      "<layer1_data><![CDATA[CS_ALM_NO_LAYER1_ADDITIONAL_DATA]]></layer1_data>\n" +
      "<sync_loss_data><![CDATA[CS_NO_SYNC_LOSS_ADDITIONAL_DATA]]></sync_loss_data>\n" +
      "<bit_error_data><![CDATA[CS_BIT_ERR_DIRECTION_IN]]></bit_error_data>\n" +
      "<nrt_alm_err_mesg/>\n" +
      "<imp id=\"line\">\n" +
      "<switch_short_name><![CDATA[00000-T7---D]]></switch_short_name>\n" +
      "<equipment_number/>\n" +
      "<directory_number><![CDATA[0000000000]]></directory_number>\n" +
      "<stroke_number><![CDATA[0]]></stroke_number>\n" +
      "</imp>\n" +
      "</imp>\n" +
      "</imp>\n" +
      "</imp>\n";
      OfflinediagnoseauftragVO auftrag = new OfflinediagnoseauftragVO();
      auftrag.setAuftragValue(wert);
      ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
      IBindingFactory bindingFactory = BindingDirectory.getFactory(OfflinediagnoseauftragVO.class);
      IMarshallingContext marshallingContext = bindingFactory.createMarshallingContext();
      marshallingContext.marshalDocument(auftrag, "ISO-8859-1", Boolean.TRUE, byteArrayOutputStream);
      String resutl = byteArrayOutputStream.toString();

      >>>>>>>>>>>>>> EXCEPTION >>>>>>>>>>>>>>>>>

      Exception while marshalling element "Wert"
      java.lang.ArrayIndexOutOfBoundsException: 4096
      at org.jibx.runtime.impl.ISO88591StreamWriter.writeTextContent(Unknown Source)
      at org.jibx.runtime.impl.MarshallingContext.element(Unknown Source)
      at de.test.es.vo.MesswertVO.JiBX_Es_diagnose_binding_marshal_1_0(MesswertVO.java)
      at de.test.es.vo.JiBX_Es_diagnose_bindingMesswertVO_access.marshal()
      at de.test.bdb.vo.JiBX_MungeAdapter.JiBX_Es_diagnose_binding_marshal_1_22()
      at de.test.es.vo.MesssystemVO.JiBX_Es_diagnose_binding_marshal_1_0(MesssystemVO.java)
      at de.test.es.vo.JiBX_Es_diagnose_bindingMesssystemVO_access.marshal()
      at de.test.bdb.vo.JiBX_MungeAdapter.JiBX_Es_diagnose_binding_marshal_1_25()
      at de.test.es.vo.DiagnoseVO.JiBX_Es_diagnose_binding_marshal_1_0(DiagnoseVO.java)
      at de.test.es.vo.OfflinediagnoseauftragVO.JiBX_Es_diagnose_binding_marshal_1_0(OfflinediagnoseauftragVO.java)
      at de.test.es.vo.JiBX_Es_diagnose_bindingOfflinediagnoseauftragVO_access.marshal()
      at de.test.es.vo.OfflinediagnoseauftragVO.marshal(OfflinediagnoseauftragVO.java)
      at org.jibx.runtime.impl.MarshallingContext.marshalRoot(Unknown Source)
      at org.jibx.runtime.impl.MarshallingContext.marshalDocument(Unknown Source)
      at de.test.shared.utils.TkpUtils.marshalOfflinediagnoseauftrag(TkpUtils.java:86)

      If you add the following lines before marshalling all works fine:
      ...
      OfflinediagnoseauftragVO auftrag = new OfflinediagnoseauftragVO();
      auftrag.setAuftragValue(wert);
      wert = wert.replaceAll("<", "#lt;");
      wert = wert.replaceAll(">", "#gt;");
      ...

        Activity

        Hide
        André Sudhoff added a comment -

        I've tried unmarshalling with large XML-data now, there seems to be no problem!

        Show
        André Sudhoff added a comment - I've tried unmarshalling with large XML-data now, there seems to be no problem!
        Hide
        Jan Finzen added a comment -

        I get a similar exception "occasionally".
        Problem is, it doesn't seem to depend directly on the input data. When I rerun the code using the same data it works fine. In fact I use a retry as a dirty workaround for that problem...

        Stacktrace:

        java.lang.ArrayIndexOutOfBoundsException: 2048

        at org.jibx.runtime.impl.ISO88591StreamWriter.writeTextContent(ISO88591StreamWriter.java(Compiled Code))
        at org.jibx.runtime.impl.MarshallingContext.element(MarshallingContext.java:698)
        at jzf.test.domain.Regelergebnis.JiBX_bindingPruefergebnis_marshal_1_0(Regelergebnis.java)
        at jzf.test.domain.JiBX_bindingPruefergebnisRegelergebnis_access.marshal()
        at jzf.test.domain.JiBX_MungeAdapter.JiBX_bindingPruefergebnis_marshal_1_8()
        at jzf.test.domain.Prueflauf.JiBX_bindingPruefergebnis_marshal_1_0(Prueflauf.java)
        at jzf.test.domain.JiBX_bindingPruefergebnisPrueflauf_access.marshal()
        at jzf.test.domain.Prueflauf.marshal(Prueflauf.java)
        at org.jibx.runtime.impl.MarshallingContext.marshalRoot(MarshallingContext.java:1035)
        at org.jibx.runtime.impl.MarshallingContext.marshalDocument(MarshallingContext.java:1083)
        at jzf.test.utils.JiBX.getErgebnisXML(JiBX.java:110)
        (...)

        Show
        Jan Finzen added a comment - I get a similar exception "occasionally". Problem is, it doesn't seem to depend directly on the input data. When I rerun the code using the same data it works fine. In fact I use a retry as a dirty workaround for that problem... Stacktrace: java.lang.ArrayIndexOutOfBoundsException: 2048 at org.jibx.runtime.impl.ISO88591StreamWriter.writeTextContent(ISO88591StreamWriter.java(Compiled Code)) at org.jibx.runtime.impl.MarshallingContext.element(MarshallingContext.java:698) at jzf.test.domain.Regelergebnis.JiBX_bindingPruefergebnis_marshal_1_0(Regelergebnis.java) at jzf.test.domain.JiBX_bindingPruefergebnisRegelergebnis_access.marshal() at jzf.test.domain.JiBX_MungeAdapter.JiBX_bindingPruefergebnis_marshal_1_8() at jzf.test.domain.Prueflauf.JiBX_bindingPruefergebnis_marshal_1_0(Prueflauf.java) at jzf.test.domain.JiBX_bindingPruefergebnisPrueflauf_access.marshal() at jzf.test.domain.Prueflauf.marshal(Prueflauf.java) at org.jibx.runtime.impl.MarshallingContext.marshalRoot(MarshallingContext.java:1035) at org.jibx.runtime.impl.MarshallingContext.marshalDocument(MarshallingContext.java:1083) at jzf.test.utils.JiBX.getErgebnisXML(JiBX.java:110) (...)
        Hide
        André Sudhoff added a comment -

        ISO88591StreamWriter.writeTextContent creates a buffer with the length as a multiple of 2KB of the input data (makespace(length)). If the input data contains a lot of characters which have to be encoded like "&", "<", ">" the buffer could be to short because the encoded charcter is 5 times longer than the original one.
        I did a patch like it exists in the UTF8StreamWriter and changed the line makespace(length) to makespace(length * 5).
        After that it works fine.

        Show
        André Sudhoff added a comment - ISO88591StreamWriter.writeTextContent creates a buffer with the length as a multiple of 2KB of the input data (makespace(length)). If the input data contains a lot of characters which have to be encoded like "&", "<", ">" the buffer could be to short because the encoded charcter is 5 times longer than the original one. I did a patch like it exists in the UTF8StreamWriter and changed the line makespace(length) to makespace(length * 5). After that it works fine.
        Hide
        Dennis Sosnoski added a comment -

        Corrected ISO88591StreamWriter to use the same multiples of character length as UTF8StreamWriter when sizing the buffer for output text.

        Show
        Dennis Sosnoski added a comment - Corrected ISO88591StreamWriter to use the same multiples of character length as UTF8StreamWriter when sizing the buffer for output text.

          People

          • Assignee:
            Dennis Sosnoski
            Reporter:
            André Sudhoff
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: