8167618: DateTimeFormatter.format() uses exceptions for flow control
Summary: Removed flow control in exception catch
Reviewed-by: rriggs, scolebourne
--- 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);
}
//-----------------------------------------------------------------------