jaxb
  1. jaxb
  2. JAXB-970

JAXB marshal if identation exceeds nested level 8

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: 2.1.10, 2.2.4u2
    • Fix Version/s: None
    • Component/s: runtime
    • Labels:
      None
    • Environment:

      JDK 1.6 and JDK 1.7

      Description

      When calling JAXB marshal with pretty print it outputs:

      <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
      <a>
      <b>
      <c>
      <d>
      <e>
      <f>
      <g>
      <h>
      <i>
      <j/>
      </i>
      </h>
      </g>
      </f>
      </e>
      </d>
      </c>
      </b>
      </a>

      The problem is when reaching indentation level 8 it restarts indentation.

      The problem is in the:
      IndentingUTF8XmlOutput.java

      buggy function:
      private void printIndent() throws IOException

      { write('\n'); int i = depth%8; write( indent8.buf, 0, i*unitLen ); i>>=3; // really i /= 8; for( ; i>0; i-- ) indent8.write(this); }

      You can see that variable i is using remainder of division with 8.
      After that i>>3 is already the remainder.
      i >>= 3 (i = i >> 3) should be instead ... i = depth >> 3;

      Other implementations does not exhibit such behavior.

        Activity

        Hide
        matejsp added a comment -

        There is another issue in Encoding class.
        indent8.write(this); does not work as it should.

        code
        Encoded e = new Encoded(indentStr);
        indent8 = new Encoded();
        indent8.ensureSize(e.len*8);
        unitLen = e.len;
        for( int i=0; i<8; i++ )
        System.arraycopy(e.buf, 0, indent8.buf, unitLen*i, unitLen);
        code

        The problem is that Encoded.ensureSize does not change the field of encoded length.

        Show
        matejsp added a comment - There is another issue in Encoding class. indent8.write(this); does not work as it should. code Encoded e = new Encoded(indentStr); indent8 = new Encoded(); indent8.ensureSize(e.len*8); unitLen = e.len; for( int i=0; i<8; i++ ) System.arraycopy(e.buf, 0, indent8.buf, unitLen*i, unitLen); code The problem is that Encoded.ensureSize does not change the field of encoded length.
        Hide
        Iaroslav Savytskyi added a comment -

        I agree with you.. It's strange.
        But I also see good thing and may be this code was written to do exactly this.

        Imagine 100x elements depth. Is it good idea to scroll to see the middle element???

        We will discuss this internally.

        Thanks a lot for reporting.

        Show
        Iaroslav Savytskyi added a comment - I agree with you.. It's strange. But I also see good thing and may be this code was written to do exactly this. Imagine 100x elements depth. Is it good idea to scroll to see the middle element??? We will discuss this internally. Thanks a lot for reporting.
        Hide
        laune added a comment -

        Also, consider the potentially huge amount of white space.

        Show
        laune added a comment - Also, consider the potentially huge amount of white space.

          People

          • Assignee:
            Iaroslav Savytskyi
            Reporter:
            matejsp
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:

              Time Tracking

              Estimated:
              Original Estimate - 1 hour
              1h
              Remaining:
              Remaining Estimate - 1 hour
              1h
              Logged:
              Time Spent - Not Specified
              Not Specified