apache / apache/kyuubi

SemanticVersion drops the minor of X.Y-SUFFIX version strings like 1.2-SNAPSHOT

Open Beginner friendly
#7,725 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Scala
Stars
2.4k
Forks
1k
PR merge metrics
No merged PRs in 30d

Description

### Describe the bug

`SemanticVersion` parses a version string with:

```scala
private val semanticVersionRegex = """^(\d+)(?:\.(\d+))?(\..*)?$""".r
```

The minor group `(?:\.(\d+))?` is optional and the trailing group `(\..*)?` also begins with a literal `.`. On `"1.2-SNAPSHOT"` the trailing group cannot match the `-`, so the engine backtracks: it drops the minor group, and the trailing group then matches `.2-SNAPSHOT` whole. The parse succeeds as `(major=1, minor=0)`, so the minor `.2` is silently lost with no parse error.

`isVersionAtLeast`/`isVersionAtMost` then compare against that wrong `(1, 0)`, so `SemanticVersion("1.2-SNAPSHOT").isVersionAtLeast("1.1")` returns `false`.

This is reachable for Flink development builds. `EnvironmentInformation.getVersion` returns strings like `X.Y-SNAPSHOT`, and `FlinkEngineUtils.checkFlinkVersion` runs them through `SemanticVersion`. A supported `1.20-SNAPSHOT` parses as `(1, 0)` and fails the version gate, while an unsupported `2.4-SNAPSHOT` parses as `(2, 0)` and passes as if it were `2.0`.

The regex first made the minor group optional in #5039 (to accept a bare major such as `"3"`); the backtracking side effect on `X.Y-SUFFIX` came with it and was never intended, since nothing pins `(1, 0)` as the expected parse of such input.

### Affects Version(s)

master (1.13.0-SNAPSHOT), and earlier releases carrying `kyuubi-util-scala`.

### Are you willing to submit PR?

Yes.

Contributor guide

Open the contributing guide

Research direction

Start at the SemanticVersion parser and its semanticVersionRegex, then trace isVersionAtLeast and isVersionAtMost. Add regression coverage for X.Y-SUFFIX inputs such as 1.2-SNAPSHOT while preserving bare-major parsing such as 3; done means the minor version is retained and Flink version gates compare correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
74/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.