diff --git a/src/java.base/share/classes/java/text/DateFormatSymbols.java b/src/java.base/share/classes/java/text/DateFormatSymbols.java index 9fff6a7c4d4..c8542ff17ee 100644 --- a/src/java.base/share/classes/java/text/DateFormatSymbols.java +++ b/src/java.base/share/classes/java/text/DateFormatSymbols.java @@ -145,10 +145,12 @@ public class DateFormatSymbols implements Serializable, Cloneable { * @throws java.util.MissingResourceException * if the resources for the specified locale cannot be * found or cannot be loaded. + * @throws NullPointerException if {@code locale} is null */ public DateFormatSymbols(Locale locale) { - initializeData(locale); + initializeData(Objects.requireNonNull(locale, + "locale should not be null")); } /** @@ -344,6 +346,7 @@ public class DateFormatSymbols implements Serializable, Cloneable { * @since 1.6 */ public static final DateFormatSymbols getInstance(Locale locale) { + Objects.requireNonNull(locale, "locale should not be null"); DateFormatSymbols dfs = getProviderInstance(locale); if (dfs != null) { return dfs; diff --git a/src/java.base/share/classes/java/text/DecimalFormatSymbols.java b/src/java.base/share/classes/java/text/DecimalFormatSymbols.java index c255b93bd98..fe512e9cc26 100644 --- a/src/java.base/share/classes/java/text/DecimalFormatSymbols.java +++ b/src/java.base/share/classes/java/text/DecimalFormatSymbols.java @@ -115,7 +115,8 @@ public class DecimalFormatSymbols implements Cloneable, Serializable { * @throws NullPointerException if {@code locale} is null */ public DecimalFormatSymbols(Locale locale) { - initialize(locale); + initialize(Objects.requireNonNull(locale, + "locale should not be null")); } /** @@ -180,6 +181,7 @@ public class DecimalFormatSymbols implements Cloneable, Serializable { * @since 1.6 */ public static final DecimalFormatSymbols getInstance(Locale locale) { + Objects.requireNonNull(locale, "locale should not be null"); LocaleProviderAdapter adapter; adapter = LocaleProviderAdapter.getAdapter(DecimalFormatSymbolsProvider.class, locale); DecimalFormatSymbolsProvider provider = adapter.getDecimalFormatSymbolsProvider(); diff --git a/test/jdk/java/text/Format/DateFormat/IntlTestDateFormatSymbols.java b/test/jdk/java/text/Format/DateFormat/IntlTestDateFormatSymbols.java index e3cb841b5c6..84b828f36c5 100644 --- a/test/jdk/java/text/Format/DateFormat/IntlTestDateFormatSymbols.java +++ b/test/jdk/java/text/Format/DateFormat/IntlTestDateFormatSymbols.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2025, 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 @@ -24,6 +24,7 @@ /* * @test * @summary test International Date Format Symbols + * @bug 8366517 * @run junit IntlTestDateFormatSymbols */ /* @@ -43,6 +44,7 @@ import java.util.*; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.fail; public class IntlTestDateFormatSymbols @@ -205,4 +207,10 @@ public class IntlTestDateFormatSymbols fail("ERROR: Clone failed"); } } + + @Test + void nullLocaleTest() { + assertThrows(NullPointerException.class, () -> new DateFormatSymbols(null)); + assertThrows(NullPointerException.class, () -> DateFormatSymbols.getInstance(null)); + } } diff --git a/test/jdk/java/text/Format/NumberFormat/IntlTestDecimalFormatSymbols.java b/test/jdk/java/text/Format/NumberFormat/IntlTestDecimalFormatSymbols.java index 75c9199c95b..c370440c932 100644 --- a/test/jdk/java/text/Format/NumberFormat/IntlTestDecimalFormatSymbols.java +++ b/test/jdk/java/text/Format/NumberFormat/IntlTestDecimalFormatSymbols.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2025, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 8282625 + * @bug 8282625 8366517 * @summary test International Decimal Format Symbols * @run junit IntlTestDecimalFormatSymbols */ @@ -44,6 +44,7 @@ import java.util.*; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.fail; public class IntlTestDecimalFormatSymbols @@ -146,4 +147,10 @@ public class IntlTestDecimalFormatSymbols fail("ERROR: Clone failed"); } } + + @Test + void nullLocaleTest() { + assertThrows(NullPointerException.class, () -> new DecimalFormatSymbols(null)); + assertThrows(NullPointerException.class, () -> DecimalFormatSymbols.getInstance(null)); + } }