On Sat, 5 Sep 2026 16:48:08 GMT, ExE Boss <[email protected]> wrote:

>> Please review this small fix.
>> 
>> **Problem:**
>> 
>> After parsing the version number, the parser enters the pre-release parsing 
>> loop regardless of whether the delimiter was `-` or `+`. As a result, 
>> build-only versions such as `1+1` are parsed as pre-release versions, 
>> causing `1+1` to compare equal to `1-1`.
>> 
>> **Fix:**
>> 
>> Record whether the version number ended with `-`, and only parse the 
>> pre-release component in that case. If it ended with `+`, proceed directly 
>> to the build component.
>> 
>> **Testing:**
>> 
>> - Added regression cases to `VersionTest.java`.
>> - `make test TEST=test/jdk/java/lang/module`: 17 passed, 0 failed.
>> 
>> 
>> 
>> 
>> ---------
>> - [x] I confirm that I make this contribution in accordance with the 
>> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai).
>
> src/java.base/share/classes/java/lang/module/ModuleDescriptor.java line 1120:
> 
>> 1118:                 else
>> 1119:                     i = takeString(v, i, pre);
>> 1120:             }
> 
> Since `parsePreRelease` is never used after entering the loop, it’d be better 
> to use an outer `if` instead:
> Suggestion:
> 
>             if (c == '-') {
>                 while (i < n) {
>                     c = v.charAt(i);
>                     if (c == '.' || c == '-') {
>                         i++;
>                         continue;
>                     }
>                     if (c == '+') {
>                         i++;
>                         break;
>                     }
>                     if (c >= '0' && c <= '9')
>                         i = takeNumber(v, i, pre);
>                     else
>                         i = takeString(v, i, pre);
>                 }
>                 
>                 if (c == '+' && i >= n) 
>                     throw new IllegalArgumentException(v + ": Empty 
> pre-release"); 
>             }

Also include the `IllegalArgumentException` check that’s on the next line 
inside this `if`:
https://github.com/openjdk/jdk/blob/d249d987974b0794ca48bfbcd96cc9a487d6f736/src/java.base/share/classes/java/lang/module/ModuleDescriptor.java#L1122-L1123

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/32715#discussion_r3941319845

Reply via email to