On Sat, 5 Sep 2026 03:43:23 GMT, Yunbo Zhang <[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);
                }
            }

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

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

Reply via email to