mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-15 01:42:37 +00:00
ICU-8927 Avoid NPE when invalid system ID is specifed in TimeZone.countEquivalentIDs and getEquivalentID.
X-SVN-Rev: 30937
This commit is contained in:
parent
8ec0200596
commit
6dfa3a52d0
2 changed files with 41 additions and 24 deletions
|
@ -218,13 +218,15 @@ public final class ZoneMeta {
|
|||
*/
|
||||
public static synchronized int countEquivalentIDs(String id) {
|
||||
int count = 0;
|
||||
try {
|
||||
UResourceBundle res = openOlsonResource(null, id);
|
||||
UResourceBundle links = res.get("links");
|
||||
int[] v = links.getIntVector();
|
||||
count = v.length;
|
||||
} catch (MissingResourceException ex) {
|
||||
// throw away
|
||||
UResourceBundle res = openOlsonResource(null, id);
|
||||
if (res != null) {
|
||||
try {
|
||||
UResourceBundle links = res.get("links");
|
||||
int[] v = links.getIntVector();
|
||||
count = v.length;
|
||||
} catch (MissingResourceException ex) {
|
||||
// throw away
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
@ -249,25 +251,25 @@ public final class ZoneMeta {
|
|||
*/
|
||||
public static synchronized String getEquivalentID(String id, int index) {
|
||||
String result = "";
|
||||
int zoneIdx = -1;
|
||||
|
||||
if (index >= 0) {
|
||||
try {
|
||||
UResourceBundle res = openOlsonResource(null, id);
|
||||
UResourceBundle links = res.get("links");
|
||||
int[] zones = links.getIntVector();
|
||||
if (index < zones.length) {
|
||||
zoneIdx = zones[index];
|
||||
UResourceBundle res = openOlsonResource(null, id);
|
||||
if (res != null) {
|
||||
int zoneIdx = -1;
|
||||
try {
|
||||
UResourceBundle links = res.get("links");
|
||||
int[] zones = links.getIntVector();
|
||||
if (index < zones.length) {
|
||||
zoneIdx = zones[index];
|
||||
}
|
||||
} catch (MissingResourceException ex) {
|
||||
// throw away
|
||||
}
|
||||
if (zoneIdx >= 0) {
|
||||
String tmp = getZoneID(zoneIdx);
|
||||
if (tmp != null) {
|
||||
result = tmp;
|
||||
}
|
||||
}
|
||||
} catch (MissingResourceException ex) {
|
||||
// throw away
|
||||
zoneIdx = -1;
|
||||
}
|
||||
}
|
||||
if (zoneIdx >= 0) {
|
||||
String tmp = getZoneID(zoneIdx);
|
||||
if (tmp != null) {
|
||||
result = tmp;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
|
|
@ -1019,6 +1019,21 @@ public class TimeZoneTest extends TestFmwk
|
|||
") returned \"" + outOfRangeID + "\", expected empty string");
|
||||
}
|
||||
}
|
||||
|
||||
// Ticket#8927 invalid system ID
|
||||
final String[] invaldIDs = {"GMT-05:00", "Hello World!", ""};
|
||||
for (String invld : invaldIDs) {
|
||||
int nEquiv = TimeZone.countEquivalentIDs(invld);
|
||||
if (nEquiv != 0) {
|
||||
errln("FAIL: countEquivalentIDs(" + invld + ") returned: " + nEquiv
|
||||
+ ", expected: 0");
|
||||
}
|
||||
String sEquiv0 = TimeZone.getEquivalentID(invld, 0);
|
||||
if (sEquiv0.length() > 0) {
|
||||
errln("FAIL: getEquivalentID(" + invld + ", 0) returned \"" + sEquiv0
|
||||
+ "\", expected empty string");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void TestCountries() {
|
||||
|
|
Loading…
Add table
Reference in a new issue