Skip to content

Commit 2052e35

Browse files
author
duke
committed
Backport 1bc13a1
1 parent 37c05c0 commit 2052e35

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

make/jdk/src/classes/build/tools/tzdb/TzdbZoneRulesCompiler.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -273,16 +273,16 @@ private void outputFile(Path dstFile, String version,
273273
// link version-region-rules
274274
out.writeShort(builtZones.size());
275275
for (Map.Entry<String, ZoneRules> entry : builtZones.entrySet()) {
276-
int regionIndex = Arrays.binarySearch(regionArray, entry.getKey());
276+
int regionIndex = findRegionIndex(regionArray, entry.getKey());
277277
int rulesIndex = rulesList.indexOf(entry.getValue());
278278
out.writeShort(regionIndex);
279279
out.writeShort(rulesIndex);
280280
}
281281
// alias-region
282282
out.writeShort(links.size());
283283
for (Map.Entry<String, String> entry : links.entrySet()) {
284-
int aliasIndex = Arrays.binarySearch(regionArray, entry.getKey());
285-
int regionIndex = Arrays.binarySearch(regionArray, entry.getValue());
284+
int aliasIndex = findRegionIndex(regionArray, entry.getKey());
285+
int regionIndex = findRegionIndex(regionArray, entry.getValue());
286286
out.writeShort(aliasIndex);
287287
out.writeShort(regionIndex);
288288
}
@@ -294,6 +294,14 @@ private void outputFile(Path dstFile, String version,
294294
}
295295
}
296296

297+
private static int findRegionIndex(String[] regionArray, String region) {
298+
int index = Arrays.binarySearch(regionArray, region);
299+
if (index < 0) {
300+
throw new IllegalArgumentException("Unknown region: " + region);
301+
}
302+
return index;
303+
}
304+
297305
/** Whether to output verbose messages. */
298306
private boolean verbose;
299307

0 commit comments

Comments
 (0)