JDK 9 RFR : java.util.logging.Formatter#formatMessage() swallows Exceptions
daniel.fuchs at oracle.com
Fri Nov 20 15:32:05 UTC 2015
On 20/11/15 15:47, Jason Mehrens wrote:
> Why not just cache the last exception in the formatter and use getTail to clear it and report it? Since formatter is in the same package as Handler you will have elevated access to the error manager through Handler.reportError. That also makes it so you don't have to change the public API of Formatter.
That would mean that you won't see the exception until
the handler is closed. Not sure whether that matters much.
ErrorManager looks already bizarre to me. But at least
with ErrorManager it looks as if someone who cares could
set his/her own ErrorManager on the formatter (with hopefully
a more sensible implementation).
I have no specific opinion on the subject I'm in favor
of taking the solution that is the least likely to cause
compatibility issues :-)
> From: core-libs-dev <core-libs-dev-bounces at openjdk.java.net> on behalf of Alexander Fomin <alexander.fomin at oracle.com>
> Sent: Friday, November 20, 2015 7:48 AM
> To: core-libs-dev at openjdk.java.net; Daniel Fuchs; mandy.chung at oracle.com
> Subject: JDK 9 RFR : java.util.logging.Formatter#formatMessage() swallows Exceptions
> please, review this patch to report errors in
> Bug: https://bugs.openjdk.java.net/browse/JDK-8137005
> Webrev: http://cr.openjdk.java.net/~dfuchs/alexander/8137005/webrev.00
> j.u.logging.Formatter#formatMessage() swallows exceptions that
> happening during formatting of a message. In the result the exceptions
> are lost and users don't know about reasons why the message hasn't been
> formatted as expected. We would avoid to throw any exceptions in
> Formatter#formatMessage() from compatibility stand point. To report an
> error in consistent way we have to pass ErrorManager in Formatter. It's
> require API changes. So, I'm going to file CCC when if the fix approved.
> The suggested fix is to add 2 new methods in j.u.logging.Formatter
> to set/get an ErrorManager, update Formatter#formatMessage() to report
> errors via the ErrorManager and update Handler to pass errorManager to
> A couple of new regression tests have been created:
> test/java/util/logging/Test8137005.java - real case provided by
> test/java/util/logging/NullErrorManagerTest.java - additional
> check to make sure no NPE showed if ErrorManager isn't set. Beside of
> this touched new API methods.
> Logging regression tests have been run:
> All tests passed passed.
> failures in the job are known issues and not related to the fix.
More information about the core-libs-dev