Skip to content

Commit 34ebcb4

Browse files
Thomas WolkensteinThomas Wolkenstein
Thomas Wolkenstein
authored and
Thomas Wolkenstein
committed
JodaOrg#524 Don't change of time zone Id in a call to DateTimeZone.forID
1 parent 7409c8b commit 34ebcb4

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

src/main/java/org/joda/time/tz/ZoneInfoProvider.java

+26-8
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
import java.lang.ref.SoftReference;
2424
import java.security.AccessController;
2525
import java.security.PrivilegedAction;
26+
import java.util.AbstractMap.SimpleEntry;
2627
import java.util.Collections;
2728
import java.util.Map;
29+
import java.util.Map.Entry;
2830
import java.util.Set;
2931
import java.util.TreeSet;
3032
import java.util.concurrent.ConcurrentHashMap;
@@ -157,22 +159,33 @@ public DateTimeZone getZone(String id) {
157159
return null;
158160
}
159161

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<?>) {
161174
@SuppressWarnings("unchecked")
162175
SoftReference<DateTimeZone> ref = (SoftReference<DateTimeZone>) obj;
163176
DateTimeZone tz = ref.get();
164177
if (tz != null) {
165178
return tz;
166179
}
167180
// Reference cleared; load data again.
168-
return loadZoneData(id);
181+
return loadZoneData(id, id);
169182
} else if (id.equals(obj)) {
170183
// Load zone data for the first time.
171-
return loadZoneData(id);
184+
return loadZoneData(id, id);
172185
}
173186

174187
// If this point is reached, mapping must link to another.
175-
return getZone((String)obj);
188+
return loadZoneData((String) obj, id);
176189
}
177190

178191
/**
@@ -231,15 +244,20 @@ public InputStream run() {
231244
/**
232245
* Loads the time zone data for one id.
233246
*
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)
235249
* @return the zone
236250
*/
237-
private DateTimeZone loadZoneData(String id) {
251+
private DateTimeZone loadZoneData(String dataId, String id) {
238252
InputStream in = null;
239253
try {
240-
in = openResource(id);
254+
in = openResource(dataId);
241255
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+
}
243261
return tz;
244262
} catch (IOException ex) {
245263
uncaughtException(ex);

0 commit comments

Comments
 (0)