From 3f35be72427da1482feba9dcbcfed3a973d258db Mon Sep 17 00:00:00 2001 From: Anubhav Meena Date: Thu, 17 Nov 2016 11:55:59 +0000 Subject: [PATCH] 8167618: DateTimeFormatter.format() uses exceptions for flow control Removed flow control in exception catch Reviewed-by: rriggs, scolebourne --- .../java/time/format/DateTimePrintContext.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/jdk/src/java.base/share/classes/java/time/format/DateTimePrintContext.java b/jdk/src/java.base/share/classes/java/time/format/DateTimePrintContext.java index 811bd5b2ee1..0faec561724 100644 --- a/jdk/src/java.base/share/classes/java/time/format/DateTimePrintContext.java +++ b/jdk/src/java.base/share/classes/java/time/format/DateTimePrintContext.java @@ -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 @@ final class DateTimePrintContext { * @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); } //-----------------------------------------------------------------------