Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8137005

java.util.logging.Formatter#formatMessage() swallows Exceptions

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version "1.8.0_51"
      Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
      Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Darwin LANELSON-mac 14.5.0 Darwin Kernel Version 14.5.0: Wed Jul 29 02:26:53 PDT 2015; root:xnu-2782.40.9~1/RELEASE_X86_64 x86_64

      A DESCRIPTION OF THE PROBLEM :
      If an object being logged throws an exception from its toString() method, then the Formatter silently swallows the exception. The format string containing tokens such as {0}, {1} etc. is output instead, but the exception is lost from this point forward.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Create a POJO.
      2. Override the toString() method so that it throws an exception from its innards.
      3. Log it using, e.g., logger.log(Level.INFO, "Problem: {0}", pojo);
      4. Observe that "Problem: {0}" is the output and the exception is lost.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I'm not expecting a particular result, although it would be nice if the exception resulting from the toString() failure were logged at a documented level before resuming with the existing behavior.

      REPRODUCIBILITY :
      This bug can be reproduced always.

            dfuchs Daniel Fuchs
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: