8219196: DataOutputStream.writeUTF may throw unexpected exceptions
Martin Buchholz
martinrb at google.com
Fri Mar 22 22:31:36 UTC 2019
No need to check for short strings in tooLongMsg.
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";
}
Otherwise looks good to me.
On Fri, Mar 22, 2019 at 1:46 PM Brian Burkhalter <
brian.burkhalter at oracle.com> wrote:
>
> On Mar 18, 2019, at 1:03 PM, Martin Buchholz <martinrb at google.com> wrote:
>
> Below is another attempt at micro-optimization (might be too tricky!), BUT:
>
>
> I like this version better and have updated the CR accordingly:
>
> http://cr.openjdk.java.net/~bpb/8219196/webrev.02/
>
> I refrained from doing a global replace of <code></code> => {@code } and
> @exception => @throws although it was tempting.
>
> - consider documenting the UTFDataFormatException and the 64k length limit
>
>
> Done; will require a CSR.
>
> - error message would actually be more useful if it contained a few chars
> from head and tail instead of length
>
>
> Done. I also changed the calculation of the length to use
> Integer.toUnsignedLong().
>
> On Mar 18, 2019, at 11:35 AM, Roger Riggs <Roger.Riggs at Oracle.com> wrote:
>
> The test only needs enough memory to create the input string (MAXINT/3+1)
> and a bit more for the default sized ByteArrayOutputStream.
> So it should run in 2G configurations.
>
>
> Fixed.
>
> Thanks,
>
> Brian
>
More information about the core-libs-dev
mailing list