8219196: DataOutputStream.writeUTF may throw unexpected exceptions

Brian Burkhalter brian.burkhalter at oracle.com
Fri Mar 22 23:32:57 UTC 2019


> On Mar 22, 2019, at 3:31 PM, Martin Buchholz <martinrb at google.com> wrote:
> 
> No need to check for short strings in tooLongMsg.

Yeah that was stupid on my part.

> Getting the actual length calculation 100% is not very important, but THIS IS JAVA so here's an attempt that looks correct even for maximal length input (untested - you could check that the exception detail gets the 3x expansion right):
> 
>     private static String tooLongMsg(String s, int bits32) {
>         int slen = s.length();
>         String head = s.substring(0, 8);
>         String tail = s.substring(slen - 8, slen);
>         // handle int overflow with max 3x expansion
>         long actualLength = (long)slen + Integer.toUnsignedLong(bits32 - slen);
>         return "encoded string (" + head + "..." + tail + ") too long: "
>             + actualLength + " bytes";
>     }

Ran the test without suppressing the exceptions and the messages look fine.

> Otherwise looks good to me.

Patch updated for the sake of formality. Don’t want to check it into the CI system until Monday.

Thanks ...


More information about the core-libs-dev mailing list