Skip to content

Commit

Permalink
8336300: DateFormatSymbols#getInstanceRef returns non-cached instance
Browse files Browse the repository at this point in the history
Reviewed-by: joehw, iris, jlu, aturbanov
  • Loading branch information
naotoj committed Jul 17, 2024
1 parent 7ec55df commit 10186ff
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 17 deletions.
16 changes: 1 addition & 15 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, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2024, 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 @@ -351,20 +351,6 @@ public static final DateFormatSymbols getInstance(Locale locale) {
throw new RuntimeException("DateFormatSymbols instance creation failed.");
}

/**
* Returns a DateFormatSymbols provided by a provider or found in
* the cache. Note that this method returns a cached instance,
* not its clone. Therefore, the instance should never be given to
* an application.
*/
static final DateFormatSymbols getInstanceRef(Locale locale) {
DateFormatSymbols dfs = getProviderInstance(locale);
if (dfs != null) {
return dfs;
}
throw new RuntimeException("DateFormatSymbols instance creation failed.");
}

private static DateFormatSymbols getProviderInstance(Locale locale) {
LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatSymbolsProvider.class, locale);
DateFormatSymbolsProvider provider = adapter.getDateFormatSymbolsProvider();
Expand Down
4 changes: 2 additions & 2 deletions src/java.base/share/classes/java/text/SimpleDateFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ public SimpleDateFormat(String pattern, Locale locale)

initializeCalendar(locale);
this.pattern = pattern;
this.formatData = DateFormatSymbols.getInstanceRef(locale);
formatData = DateFormatSymbols.getInstance(locale);
this.locale = locale;
initialize(locale);
}
Expand All @@ -644,7 +644,7 @@ public SimpleDateFormat(String pattern, DateFormatSymbols formatSymbols)
}

this.pattern = pattern;
this.formatData = (DateFormatSymbols) formatSymbols.clone();
formatData = (DateFormatSymbols) formatSymbols.clone();
this.locale = Locale.getDefault(Locale.Category.FORMAT);
initializeCalendar(this.locale);
initialize(this.locale);
Expand Down

1 comment on commit 10186ff

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

Please sign in to comment.