DateTimeFormatter.format() uses exceptions for flow control

Roger Riggs Roger.Riggs at Oracle.com
Wed Oct 12 15:57:19 UTC 2016


Created an issue [1] and included the patch.

Thanks, Roger

[1] https://bugs.openjdk.java.net/browse/JDK-8167618


On 10/10/2016 2:53 AM, Clément MATHIEU wrote:
> On Mon, 2016-10-10 at 06:47 +1000, David Holmes wrote:
>
> Hi David,
>
>> Please note that patches can only be accepted if they are sent
>> through, or hosted upon OpenJDK infrastructure. If the patch is small
>> enough can you send it inline in the email (attachments are often
>> stripped)
> Here it is:
>
> --- 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;
>           }
>       }
>
> Clément MATHIEU



More information about the core-libs-dev mailing list