8250678: ModuleDescriptor.Version parsing treats empty segments inconsistently

Reviewed-by: mchung, alanb
This commit is contained in:
Masanori Yano 2021-11-09 14:28:07 +00:00 committed by Alan Bateman
parent 4bd5bfd8e2
commit e198594753
2 changed files with 12 additions and 15 deletions
src/java.base/share/classes/java/lang/module
test/jdk/java/lang/module

@ -1033,13 +1033,6 @@ public class ModuleDescriptor
while (i < n) {
c = v.charAt(i);
if (c >= '0' && c <= '9')
i = takeNumber(v, i, pre);
else
i = takeString(v, i, pre);
if (i >= n)
break;
c = v.charAt(i);
if (c == '.' || c == '-') {
i++;
continue;
@ -1048,6 +1041,10 @@ public class ModuleDescriptor
i++;
break;
}
if (c >= '0' && c <= '9')
i = takeNumber(v, i, pre);
else
i = takeString(v, i, pre);
}
if (c == '+' && i >= n)
@ -1055,17 +1052,14 @@ public class ModuleDescriptor
while (i < n) {
c = v.charAt(i);
if (c >= '0' && c <= '9')
i = takeNumber(v, i, build);
else
i = takeString(v, i, build);
if (i >= n)
break;
c = v.charAt(i);
if (c == '.' || c == '-' || c == '+') {
i++;
continue;
}
if (c >= '0' && c <= '9')
i = takeNumber(v, i, build);
else
i = takeString(v, i, build);
}
this.version = v;

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2021, 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
@ -148,6 +148,9 @@ public class VersionTest {
{ "1", "1.0.0" },
{ "1.0", "1.0.0" },
{ "1.0-beta", "1.0.0-beta" },
{ "1.0-1.1", "1.0-1..1" },
{ "1.0-1+1", "1.0-1.+1" },
{ "1.0-1+1.1", "1.0-1+1..1" },
};
}