java.util.logging.FileHandler integer overflow prevents file rotation

Stanimir Simeonoff stanimir at riflexo.com
Tue Aug 19 08:06:27 UTC 2014


java.util.logging.FileHandler uses ints to track the written bytes
that can cause negative value for
java.util.logging.FileHandler.MeteredStream.written as there is no
check in any of the write methods.
The overflow prevents the check in FileHandler.publish(LogRecord)
meter.written >= limit to ever trigger, esp. setting limit to
Integer.MAX_VALUE that effectively always prevents file rotation.

On a flip note, MeteredStream should be a static class.
On another flip note, FileHandler should be using long as part of the
API and internal implementation. ints are limited to 2GiB even when
properly implemented that's a relatively low amount for certain types
of logging files. So I propose adding overloaded c-tors
 FileHandler(String pattern, long limit, int count, boolean append)
and FileHandler(String pattern, long limit, int count). LogManager
should have a method "long getLongProperty(String name, long
defaultValue)" to initialize limit.

Thanks
Stanimir



More information about the core-libs-dev mailing list