jaxb-ri icon indicating copy to clipboard operation
jaxb-ri copied to clipboard

JAXB marshal if identation exceeds nested level 8

Open Tomas-Kraus opened this issue 11 years ago • 7 comments

When calling JAXB marshal with pretty print it outputs:

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.

Environment

JDK 1.6 and JDK 1.7

Affected Versions

[2.1.10, 2.2.4u2]

Tomas-Kraus avatar Jul 25 '13 18:07 Tomas-Kraus

  • Issue Imported From: https://github.com/javaee/jaxb-v2/issues/970
  • Original Issue Raised By:@glassfishrobot
  • Original Issue Assigned To: @glassfishrobot

Tomas-Kraus avatar Sep 21 '18 16:09 Tomas-Kraus

@glassfishrobot Commented Reported by matejsp

Tomas-Kraus avatar Jul 25 '13 18:07 Tomas-Kraus

@glassfishrobot Commented matejsp said: 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.len8); unitLen = e.len; for( int i=0; i<8; i++ ) System.arraycopy(e.buf, 0, indent8.buf, unitLeni, unitLen); code

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

Tomas-Kraus avatar Dec 24 '13 09:12 Tomas-Kraus

@glassfishrobot Commented yaroska said: 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.

Tomas-Kraus avatar Jan 09 '14 14:01 Tomas-Kraus

@glassfishrobot Commented laune said: Also, consider the potentially huge amount of white space.

Tomas-Kraus avatar Jan 09 '14 14:01 Tomas-Kraus

@glassfishrobot Commented Was assigned to yaroska

Tomas-Kraus avatar Jul 25 '13 18:07 Tomas-Kraus

@glassfishrobot Commented This issue was imported from java.net JIRA JAXB-970

Tomas-Kraus avatar Apr 24 '17 12:04 Tomas-Kraus