JDK-6456978 : Cache of ResourceBundles does not work properly in DateFormatSymbols
Type:Bug
Component:core-libs
Sub-Component:java.text
Affected Version:6
Priority:P4
Status:Closed
Resolution:Duplicate
OS:generic
CPU:generic
Submitted:2006-08-03
Updated:2010-10-14
Resolved:2010-10-14
The Version table provides details related to the release that this issue/RFE will be addressed.
Unresolved : Release in which this issue/RFE will be addressed. Resolved: Release in which this issue/RFE has been resolved. Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.
In DateFormatSymbols' method cacheLookup(), once the GC ocurred and the SoftReference's referent (ResourceBundle instance) was cleared, it does not put the created SoftReference instance into the cache.
Comments
SUGGESTED FIX
Here is a suggested fix (including generification):
*** DateFormatSymbols.java.orig Thu Aug 3 14:35:14 2006
--- DateFormatSymbols.java Thu Aug 3 14:33:54 2006
***************
*** 558,564 ****
* Cache to hold the FormatData and TimeZoneNames ResourceBundles
* of a Locale.
*/
! private static Hashtable cachedLocaleData = new Hashtable(3);
/**
* Look up resource data for the desiredLocale in the cache; update the
--- 558,565 ----
* Cache to hold the FormatData and TimeZoneNames ResourceBundles
* of a Locale.
*/
! private static Hashtable<Locale, SoftReference<ResourceBundle>> cachedLoca
leData =
! new Hashtable<Locale, SoftReference<ResourceBundle>>(3);
/**
* Look up resource data for the desiredLocale in the cache; update the
***************
*** 566,581 ****
*/
private static ResourceBundle cacheLookup(Locale desiredLocale) {
ResourceBundle rb;
! SoftReference data
! = (SoftReference)cachedLocaleData.get(desiredLocale);
if (data == null) {
rb = LocaleData.getDateFormatData(desiredLocale);
! data = new SoftReference(rb);
cachedLocaleData.put(desiredLocale, data);
} else {
! if ((rb = (ResourceBundle)data.get()) == null) {
rb = LocaleData.getDateFormatData(desiredLocale);
! data = new SoftReference(rb);
}
}
return rb;
--- 567,583 ----
*/
private static ResourceBundle cacheLookup(Locale desiredLocale) {
ResourceBundle rb;
! SoftReference<ResourceBundle> data
! = cachedLocaleData.get(desiredLocale);
if (data == null) {
rb = LocaleData.getDateFormatData(desiredLocale);
! data = new SoftReference<ResourceBundle>(rb);
cachedLocaleData.put(desiredLocale, data);
} else {
! if ((rb = data.get()) == null) {
rb = LocaleData.getDateFormatData(desiredLocale);
! data = new SoftReference<ResourceBundle>(rb);
! cachedLocaleData.put(desiredLocale, data);
}
}
return rb;