8340554: Improve MessageFormat readObject checks

Reviewed-by: naoto
This commit is contained in:
Justin Lu 2024-10-24 16:17:43 +00:00
parent 7d5eefa506
commit 7af46a6b42
2 changed files with 9 additions and 3 deletions

View File

@ -2041,7 +2041,7 @@ public class MessageFormat extends Format {
// Check the correctness of arguments and offsets
if (isValid) {
int lastOffset = patt.length() + 1;
int lastOffset = patt.length();
for (int i = maxOff; i >= 0; --i) {
if (argNums[i] < 0 || argNums[i] >= MAX_ARGUMENT_INDEX
|| offs[i] < 0 || offs[i] > lastOffset) {

View File

@ -23,7 +23,7 @@
/*
* @test
* @bug 8331446
* @bug 8331446 8340554
* @summary Check correctness of deserialization
* @run junit SerializationTest
*/
@ -70,7 +70,13 @@ public class SerializationTest {
// With null locale. (NPE not thrown, if no format defined)
new MessageFormat("{1} {0} foo", null),
// With formats
new MessageFormat("{0,number,short} {0} {1,date,long} foo")
new MessageFormat("{0,number,short} {0} {1,date,long} foo"),
// Offset equal to pattern length (0)
new MessageFormat("{0}"),
// Offset equal to pattern length (1)
new MessageFormat("X{0}"),
// Offset 1 under pattern length
new MessageFormat("X{0}X")
);
}