Skip to content

Commit 3824c7c

Browse files
committed
8366517: Refine null locale processing of ctor/factory methods in Date/DecimalFormatSymbols
Reviewed-by: jlu, rriggs
1 parent 4ab2b5b commit 3824c7c

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

src/java.base/share/classes/java/text/DateFormatSymbols.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,12 @@ public DateFormatSymbols()
145145
* @throws java.util.MissingResourceException
146146
* if the resources for the specified locale cannot be
147147
* found or cannot be loaded.
148+
* @throws NullPointerException if {@code locale} is null
148149
*/
149150
public DateFormatSymbols(Locale locale)
150151
{
151-
initializeData(locale);
152+
initializeData(Objects.requireNonNull(locale,
153+
"locale should not be null"));
152154
}
153155

154156
/**
@@ -344,6 +346,7 @@ public static final DateFormatSymbols getInstance() {
344346
* @since 1.6
345347
*/
346348
public static final DateFormatSymbols getInstance(Locale locale) {
349+
Objects.requireNonNull(locale, "locale should not be null");
347350
DateFormatSymbols dfs = getProviderInstance(locale);
348351
if (dfs != null) {
349352
return dfs;

src/java.base/share/classes/java/text/DecimalFormatSymbols.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ public DecimalFormatSymbols() {
115115
* @throws NullPointerException if {@code locale} is null
116116
*/
117117
public DecimalFormatSymbols(Locale locale) {
118-
initialize(locale);
118+
initialize(Objects.requireNonNull(locale,
119+
"locale should not be null"));
119120
}
120121

121122
/**
@@ -180,6 +181,7 @@ public static final DecimalFormatSymbols getInstance() {
180181
* @since 1.6
181182
*/
182183
public static final DecimalFormatSymbols getInstance(Locale locale) {
184+
Objects.requireNonNull(locale, "locale should not be null");
183185
LocaleProviderAdapter adapter;
184186
adapter = LocaleProviderAdapter.getAdapter(DecimalFormatSymbolsProvider.class, locale);
185187
DecimalFormatSymbolsProvider provider = adapter.getDecimalFormatSymbolsProvider();

test/jdk/java/text/Format/DateFormat/IntlTestDateFormatSymbols.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -24,6 +24,7 @@
2424
/*
2525
* @test
2626
* @summary test International Date Format Symbols
27+
* @bug 8366517
2728
* @run junit IntlTestDateFormatSymbols
2829
*/
2930
/*
@@ -43,6 +44,7 @@
4344

4445
import org.junit.jupiter.api.Test;
4546

47+
import static org.junit.jupiter.api.Assertions.assertThrows;
4648
import static org.junit.jupiter.api.Assertions.fail;
4749

4850
public class IntlTestDateFormatSymbols
@@ -205,4 +207,10 @@ public void TestSymbols()
205207
fail("ERROR: Clone failed");
206208
}
207209
}
210+
211+
@Test
212+
void nullLocaleTest() {
213+
assertThrows(NullPointerException.class, () -> new DateFormatSymbols(null));
214+
assertThrows(NullPointerException.class, () -> DateFormatSymbols.getInstance(null));
215+
}
208216
}

test/jdk/java/text/Format/NumberFormat/IntlTestDecimalFormatSymbols.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
2323

2424
/*
2525
* @test
26-
* @bug 8282625
26+
* @bug 8282625 8366517
2727
* @summary test International Decimal Format Symbols
2828
* @run junit IntlTestDecimalFormatSymbols
2929
*/
@@ -44,6 +44,7 @@
4444

4545
import org.junit.jupiter.api.Test;
4646

47+
import static org.junit.jupiter.api.Assertions.assertThrows;
4748
import static org.junit.jupiter.api.Assertions.fail;
4849

4950
public class IntlTestDecimalFormatSymbols
@@ -146,4 +147,10 @@ public void TestSymbols()
146147
fail("ERROR: Clone failed");
147148
}
148149
}
150+
151+
@Test
152+
void nullLocaleTest() {
153+
assertThrows(NullPointerException.class, () -> new DecimalFormatSymbols(null));
154+
assertThrows(NullPointerException.class, () -> DecimalFormatSymbols.getInstance(null));
155+
}
149156
}

0 commit comments

Comments
 (0)