From f8e8fc7e29f9b27bc6031804f916c34b8ef5a83e Mon Sep 17 00:00:00 2001 From: Justin Lu Date: Mon, 27 Mar 2023 21:36:14 +0000 Subject: [PATCH] 8177352: Calendar.getDisplayName(s) in non-lenient mode inconsistent, does not match spec Reviewed-by: naoto --- .../share/classes/java/util/Calendar.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/java.base/share/classes/java/util/Calendar.java b/src/java.base/share/classes/java/util/Calendar.java index 361733dabec..6d0761191dc 100644 --- a/src/java.base/share/classes/java/util/Calendar.java +++ b/src/java.base/share/classes/java/util/Calendar.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2023, 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 @@ -2077,6 +2077,12 @@ public abstract class Calendar implements Serializable, Cloneable, ComparableIf there is no string representation of the {@code Calendar} {@code field} + * and the calendar is in non-lenient mode and any calendar fields have invalid values, + * {@code null} is returned. If there is a string representation of the {@code Calendar} + * {@code field} and the calendar is in non-lenient mode and any calendar fields + * have invalid values, {@code IllegalArgumentException} will be thrown. + * * @param field * the calendar field for which the string representation * is returned @@ -2170,6 +2176,12 @@ public abstract class Calendar implements Serializable, Cloneable, ComparableUnlike {@link #getDisplayName(int, int, Locale)}, this + * method will not throw an {@code IllegalArgumentException} if the + * {@code Calendar} is non-lenient and any of the calendar fields have + * invalid values. Instead, this method will return either {@code null} or + * a {@code Map}. + * * @param field * the calendar field for which the display names are returned * @param style @@ -2184,9 +2196,7 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable