8319640: ClassicFormat::parseObject (from DateTimeFormatter) does not conform to the javadoc and may leak DateTimeException

Reviewed-by: rriggs, iris, jlu, joehw
This commit is contained in:
Naoto Sato 2023-11-13 23:42:40 +00:00
parent 1802cb566e
commit fe0ccdf5f8
2 changed files with 42 additions and 16 deletions

View file

@ -2296,29 +2296,23 @@ public final class DateTimeFormatter {
DateTimeParseContext context;
try {
context = formatter.parseUnresolved0(text, pos);
} catch (IndexOutOfBoundsException ex) {
if (pos.getErrorIndex() < 0) {
pos.setErrorIndex(0);
if (context == null) {
if (pos.getErrorIndex() < 0) {
pos.setErrorIndex(0);
}
return null;
}
return null;
}
if (context == null) {
if (pos.getErrorIndex() < 0) {
pos.setErrorIndex(0);
}
return null;
}
try {
TemporalAccessor resolved = context.toResolved(formatter.resolverStyle, formatter.resolverFields);
if (parseType == null) {
return resolved;
}
return resolved.query(parseType);
} catch (RuntimeException ex) {
pos.setErrorIndex(0);
if (pos.getErrorIndex() < 0) {
pos.setErrorIndex(0);
}
return null;
}
}
}
}