[jdom-interest] Question about element length

Rosen, Alex arosen at silverstream.com
Wed Aug 23 08:21:25 PDT 2000


> Regardless, I don't believe Java has a String length restriction.  I
> just wrote a sample program that constructs a 1,000,000 character
> string, and it worked fine.  Now I seem to recall method bodies have a
> 64K restriction; maybe you're thinking of that.
>
> -jh-

When you serialize a String, it uses DataOutput.writeUTF(), which prefixes the string
with a two-byte representation of the number of bytes in the string. Therefore, the
serialized String is limited to 64K of UTF-8 bytes (not chars). Which is a pretty nasty
bug, but they couldn't figure out how to fix it in a backward-compatible way. I vaguely
recall that they were somehow going to fix this for some JDK release, but I don't
remember which one.

Alex

P.S. Thanks for the mailing list help.



More information about the jdom-interest mailing list