jaxb-ri
jaxb-ri copied to clipboard
JAXB marshal if identation exceeds nested level 8
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]
- Issue Imported From: https://github.com/javaee/jaxb-v2/issues/970
- Original Issue Raised By:@glassfishrobot
- Original Issue Assigned To: @glassfishrobot
@glassfishrobot Commented Reported by matejsp
@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.
@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.
@glassfishrobot Commented laune said: Also, consider the potentially huge amount of white space.
@glassfishrobot Commented Was assigned to yaroska
@glassfishrobot Commented This issue was imported from java.net JIRA JAXB-970