Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/java.base/share/classes/java/text/DateFormatSymbols.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 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
Expand Down Expand Up @@ -145,10 +145,12 @@ public DateFormatSymbols()
* @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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding an explicit Objects.requireNull(locale, "locale") would clearly identify when the NPE is thrown.
Though it might be earlier than without the check.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. Added the explicit null check. (and a test case)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are adding an explicit check to the ctor, might we also take this opportunity to add the check to the related 1-arg factory method?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. Also did the same for DecimalFormatSymbols.

*/
public DateFormatSymbols(Locale locale)
{
initializeData(locale);
initializeData(Objects.requireNonNull(locale,
"locale should not be null"));
}

/**
Expand Down Expand Up @@ -344,6 +346,7 @@ public static final DateFormatSymbols getInstance() {
* @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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ public DecimalFormatSymbols() {
* @throws NullPointerException if {@code locale} is null
*/
public DecimalFormatSymbols(Locale locale) {
initialize(locale);
initialize(Objects.requireNonNull(locale,
"locale should not be null"));
}

/**
Expand Down Expand Up @@ -180,6 +181,7 @@ public static final DecimalFormatSymbols getInstance() {
* @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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -24,6 +24,7 @@
/*
* @test
* @summary test International Date Format Symbols
* @bug 8366517
* @run junit IntlTestDateFormatSymbols
*/
/*
Expand All @@ -43,6 +44,7 @@

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
Expand Down Expand Up @@ -205,4 +207,10 @@ public void TestSymbols()
fail("ERROR: Clone failed");
}
}

@Test
void nullLocaleTest() {
assertThrows(NullPointerException.class, () -> new DateFormatSymbols(null));
assertThrows(NullPointerException.class, () -> DateFormatSymbols.getInstance(null));
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -23,7 +23,7 @@

/*
* @test
* @bug 8282625
* @bug 8282625 8366517
* @summary test International Decimal Format Symbols
* @run junit IntlTestDecimalFormatSymbols
*/
Expand All @@ -44,6 +44,7 @@

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
Expand Down Expand Up @@ -146,4 +147,10 @@ public void TestSymbols()
fail("ERROR: Clone failed");
}
}

@Test
void nullLocaleTest() {
assertThrows(NullPointerException.class, () -> new DecimalFormatSymbols(null));
assertThrows(NullPointerException.class, () -> DecimalFormatSymbols.getInstance(null));
}
}