# HG changeset patch # User ameena # Date 1479383759 0 # Node ID c229da92b1a93b56cf52e511565ba52de0127a89 # Parent 9ab10842acf7cfb8c68b481db407f4c9953fd7de 8167618: DateTimeFormatter.format() uses exceptions for flow control Summary: Removed flow control in exception catch Reviewed-by: rriggs, scolebourne diff -r 9ab10842acf7 -r c229da92b1a9 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); } //-----------------------------------------------------------------------