8167618: DateTimeFormatter.format() uses exceptions for flow control
authorameena
Thu, 17 Nov 2016 11:55:59 +0000
changeset 42160 c229da92b1a9
parent 42159 9ab10842acf7
child 42161 5b0b84715c06
8167618: DateTimeFormatter.format() uses exceptions for flow control Summary: Removed flow control in exception catch Reviewed-by: rriggs, scolebourne
jdk/src/java.base/share/classes/java/time/format/DateTimePrintContext.java
--- a/jdk/src/java.base/share/classes/java/time/format/DateTimePrintContext.java	Thu Nov 17 11:40:50 2016 +0530
+++ b/jdk/src/java.base/share/classes/java/time/format/DateTimePrintContext.java	Thu Nov 17 11:55:59 2016 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -302,14 +302,10 @@
      * @throws DateTimeException if the field is not available and the section is not optional
      */
     Long getValue(TemporalField field) {
-        try {
-            return temporal.getLong(field);
-        } catch (DateTimeException ex) {
-            if (optional > 0) {
-                return null;
-            }
-            throw ex;
+        if (optional > 0 && !temporal.isSupported(field)) {
+            return null;
         }
+        return temporal.getLong(field);
     }
 
     //-----------------------------------------------------------------------