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

DateTimeFormatter.format() uses exceptions for flow control

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 8
    • Fix Version/s: 9
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      b147

      Description

      DateTimePrintContext.getValue() relies on exceptions to
      handle optionality. Using exceptions for flow control seems both
      unexpected and very costly.

      Ref: http://mail.openjdk.java.net/pipermail/core-libs-dev/2016-October/044048.html

      Patch contributed by: Clément MATHIEU <clement@unportant.info>

      --- old/src/java.base/share/classes/java/time/format/DateTimePrintContext.java 2016-10-09 17:01:30.326739656 +0200
      +++ new/src/java.base/share/classes/java/time/format/DateTimePrintContext.java 2016-10-09 17:01:30.228738595 +0200
      @@ -302,13 +302,10 @@
            * @throws DateTimeException if the field is not available and the section is not optional
            */
           Long getValue(TemporalField field) {
      - try {
      + if (optional == 0) {
                   return temporal.getLong(field);
      - } catch (DateTimeException ex) {
      - if (optional > 0) {
      - return null;
      - }
      - throw ex;
      + } else {
      + return temporal.isSupported(field) ? temporal.getLong(field) : null;
               }
           }

        Activity

        Hide
        hgupdate HG Updates added a comment -
        URL: http://hg.openjdk.java.net/jdk9/dev/jdk/rev/83a3ab863b96
        User: ntv
        Date: 2016-11-17 11:56:54 +0000
        Show
        hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/dev/jdk/rev/83a3ab863b96 User: ntv Date: 2016-11-17 11:56:54 +0000
        Hide
        hgupdate HG Updates added a comment -
        URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/83a3ab863b96
        User: lana
        Date: 2016-11-30 21:39:08 +0000
        Show
        hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/83a3ab863b96 User: lana Date: 2016-11-30 21:39:08 +0000

          People

          • Assignee:
            ameena Anubhav Meena (Inactive)
            Reporter:
            rriggs Roger Riggs
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: