mirror of
https://github.com/openjdk/jdk.git
synced 2026-01-28 12:09:14 +00:00
8366517: Refine null locale processing of ctor/factory methods in Date/DecimalFormatSymbols
Reviewed-by: jlu, rriggs
This commit is contained in:
parent
4ab2b5bdb4
commit
3824c7cd06
@ -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;
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user