|
23 | 23 | import java.lang.ref.SoftReference;
|
24 | 24 | import java.security.AccessController;
|
25 | 25 | import java.security.PrivilegedAction;
|
| 26 | +import java.util.AbstractMap.SimpleEntry; |
26 | 27 | import java.util.Collections;
|
27 | 28 | import java.util.Map;
|
| 29 | +import java.util.Map.Entry; |
28 | 30 | import java.util.Set;
|
29 | 31 | import java.util.TreeSet;
|
30 | 32 | import java.util.concurrent.ConcurrentHashMap;
|
@@ -157,22 +159,33 @@ public DateTimeZone getZone(String id) {
|
157 | 159 | return null;
|
158 | 160 | }
|
159 | 161 |
|
160 |
| - if (obj instanceof SoftReference<?>) { |
| 162 | + if (obj instanceof Entry) { |
| 163 | + // If this point is reached, mapping must link to another. |
| 164 | + @SuppressWarnings("unchecked") |
| 165 | + Entry<String, SoftReference<DateTimeZone>> entry = (Entry<String, SoftReference<DateTimeZone>>) obj; |
| 166 | + SoftReference<DateTimeZone> ref = entry.getValue(); |
| 167 | + DateTimeZone tz = ref.get(); |
| 168 | + if (tz != null) { |
| 169 | + return tz; |
| 170 | + } |
| 171 | + // Reference cleared; load data again. |
| 172 | + return loadZoneData(entry.getKey(), id); |
| 173 | + } else if (obj instanceof SoftReference<?>) { |
161 | 174 | @SuppressWarnings("unchecked")
|
162 | 175 | SoftReference<DateTimeZone> ref = (SoftReference<DateTimeZone>) obj;
|
163 | 176 | DateTimeZone tz = ref.get();
|
164 | 177 | if (tz != null) {
|
165 | 178 | return tz;
|
166 | 179 | }
|
167 | 180 | // Reference cleared; load data again.
|
168 |
| - return loadZoneData(id); |
| 181 | + return loadZoneData(id, id); |
169 | 182 | } else if (id.equals(obj)) {
|
170 | 183 | // Load zone data for the first time.
|
171 |
| - return loadZoneData(id); |
| 184 | + return loadZoneData(id, id); |
172 | 185 | }
|
173 | 186 |
|
174 | 187 | // If this point is reached, mapping must link to another.
|
175 |
| - return getZone((String)obj); |
| 188 | + return loadZoneData((String) obj, id); |
176 | 189 | }
|
177 | 190 |
|
178 | 191 | /**
|
@@ -231,15 +244,20 @@ public InputStream run() {
|
231 | 244 | /**
|
232 | 245 | * Loads the time zone data for one id.
|
233 | 246 | *
|
234 |
| - * @param id the id to load |
| 247 | + * @param dataId the id of the time zone in the time zone data base (for renamed time zones this is the new one) |
| 248 | + * @param id the id of the time zone in the returned object (for renamed time zones this is the old one) |
235 | 249 | * @return the zone
|
236 | 250 | */
|
237 |
| - private DateTimeZone loadZoneData(String id) { |
| 251 | + private DateTimeZone loadZoneData(String dataId, String id) { |
238 | 252 | InputStream in = null;
|
239 | 253 | try {
|
240 |
| - in = openResource(id); |
| 254 | + in = openResource(dataId); |
241 | 255 | DateTimeZone tz = DateTimeZoneBuilder.readFrom(in, id);
|
242 |
| - iZoneInfoMap.put(id, new SoftReference<DateTimeZone>(tz)); |
| 256 | + if (!dataId.equals(id)) { |
| 257 | + iZoneInfoMap.put(id, new SimpleEntry<String, SoftReference<DateTimeZone>>(dataId, new SoftReference<DateTimeZone>(tz))); |
| 258 | + } else { |
| 259 | + iZoneInfoMap.put(id, new SoftReference<DateTimeZone>(tz)); |
| 260 | + } |
243 | 261 | return tz;
|
244 | 262 | } catch (IOException ex) {
|
245 | 263 | uncaughtException(ex);
|
|
0 commit comments