Skip to content

8339803: Acknowledge case insensitive unambiguous keywords in tzdata files #632

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 14 additions & 30 deletions jdk/make/src/classes/build/tools/tzdb/TzdbZoneRulesCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ private void outputFile(Path dstFile, String version,
}
}

private static final Pattern YEAR = Pattern.compile("(?i)(?<min>min)|(?<max>max)|(?<only>only)|(?<year>[0-9]+)");
private static final Matcher TIME = Pattern.compile("(?<neg>-)?+(?<hour>[0-9]{1,2})(:(?<minute>[0-5][0-9]))?+(:(?<second>[0-5][0-9]))?+").matcher("");

/** The TZDB rules. */
Expand Down Expand Up @@ -330,7 +329,8 @@ private void parseFile(Path file) throws Exception {
} else {
if (s.hasNext()) {
String first = s.next();
if (first.equals("Zone")) {
int len = first.length();
if (first.regionMatches(true, 0, "Zone", 0, len)) {
openZone = new ArrayList<>();
try {
zones.put(s.next(), openZone);
Expand All @@ -343,14 +343,14 @@ private void parseFile(Path file) throws Exception {
}
} else {
openZone = null;
if (first.equals("Rule")) {
if (first.regionMatches(true, 0, "Rule", 0, len)) {
try {
parseRuleLine(s);
} catch (NoSuchElementException x) {
printVerbose("Invalid Rule line in file: " + file + ", line: " + line);
throw new IllegalArgumentException("Invalid Rule line");
}
} else if (first.equals("Link")) {
} else if (first.regionMatches(true, 0, "Link", 0, len)) {
try {
String realId = s.next();
String aliasId = s.next();
Expand Down Expand Up @@ -440,7 +440,7 @@ private void parseMonthDayTime(Scanner s, TZDBMonthDayTime mdt) {
mdt.month = parseMonth(s);
if (s.hasNext()) {
String dayRule = s.next();
if (dayRule.startsWith("last")) {
if (dayRule.regionMatches(true, 0, "last", 0, 4)) {
mdt.dayOfMonth = -1;
mdt.dayOfWeek = parseDayOfWeek(dayRule.substring(4));
mdt.adjustForwards = false;
Expand Down Expand Up @@ -473,31 +473,15 @@ private void parseMonthDayTime(Scanner s, TZDBMonthDayTime mdt) {
}
}

private int parseYear(Scanner s, int defaultYear) {
if (s.hasNext(YEAR)) {
s.next(YEAR);
MatchResult mr = s.match();
if (mr.group(1) != null) {
return 1900; // systemv has min
} else if (mr.group(2) != null) {
return YEAR_MAX_VALUE;
} else if (mr.group(3) != null) {
return defaultYear;
}
return Integer.parseInt(mr.group(4));
/*
if (mr.group("min") != null) {
//return YEAR_MIN_VALUE;
return 1900; // systemv has min
} else if (mr.group("max") != null) {
return YEAR_MAX_VALUE;
} else if (mr.group("only") != null) {
return defaultYear;
}
return Integer.parseInt(mr.group("year"));
*/
}
throw new IllegalArgumentException("Unknown year: " + s.next());
int parseYear(Scanner s, int defaultYear) {
String year = s.next();
int len = year.length();

if (year.regionMatches(true, 0, "minimum", 0, len)) return 1900;
if (year.regionMatches(true, 0, "maximum", 0, len)) return YEAR_MAX_VALUE;
if (year.regionMatches(true, 0, "only", 0, len)) return defaultYear;

return Integer.parseInt(year);
}

private int parseMonth(Scanner s) {
Expand Down
9 changes: 5 additions & 4 deletions jdk/test/sun/util/calendar/zi/RuleRec.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -170,12 +170,13 @@ static RuleRec parse(StringTokenizer tokens) {
rec.toYear = Integer.parseInt(token);
} catch (NumberFormatException e) {
// it's not integer
if ("min".equals(token) || "minimum".equals(token)) {
int len = token.length();
if (token.regionMatches(true, 0, "minimum", 0, len)) {
rec.fromYear = Zoneinfo.getMinYear();
} else if ("max".equals(token) || "maximum".equals(token)) {
} else if (token.regionMatches(true, 0, "maximum", 0, len)) {
rec.toYear = Integer.MAX_VALUE;
rec.isLastRule = true;
} else if ("only".equals(token)) {
} else if (token.regionMatches(true, 0, "only", 0, len)) {
rec.toYear = rec.fromYear;
} else {
Main.panic("invalid year value: "+token);
Expand Down
7 changes: 4 additions & 3 deletions jdk/test/sun/util/calendar/zi/Zoneinfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,9 @@ static Zoneinfo parse(String fname) {
continue;
}
String token = tokens.nextToken();
int len = token.length();

if (continued || "Zone".equals(token)) {
if (continued || token.regionMatches(true, 0, "Zone", 0, len)){
if (zone == null) {
if (!tokens.hasMoreTokens()) {
panic("syntax error: zone no more token");
Expand All @@ -270,7 +271,7 @@ static Zoneinfo parse(String fname) {
}
zone = null;
}
} else if ("Rule".equals(token)) {
} else if (token.regionMatches(true, 0, "Rule", 0, len)) {
if (!tokens.hasMoreTokens()) {
panic("syntax error: rule no more token");
}
Expand All @@ -283,7 +284,7 @@ static Zoneinfo parse(String fname) {
RuleRec rrec = RuleRec.parse(tokens);
rrec.setLine(line);
rule.add(rrec);
} else if ("Link".equals(token)) {
} else if (token.regionMatches(true, 0, "Link", 0, len)) {
// Link <newname> <oldname>
try {
String name1 = tokens.nextToken();
Expand Down