pick-kotlin-version.py: tolerate warnings#19865
Merged
Conversation
This commit changes pick-kotlin-version.py to use re.search() instead of re.match(), so that it can better cope with warning messages.
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR updates the Kotlin version detection script to use re.search() instead of re.match(), allowing it to find the version string even when warning lines precede it.
- Switch from
re.match()tore.search()in the version regex - Simplify the regex by removing leading/trailing wildcard matches
- Preserve existing exception handling for parsing failures
Comments suppressed due to low confidence (1)
java/kotlin-extractor/pick-kotlin-version.py:29
- Add a unit test for
pick-kotlin-version.pythat simulateskotlinc -versionoutput containing warning lines before the version string, to ensure the regex continues to match correctly.
m = re.search(r' kotlinc-jvm ([0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z][a-zA-Z0-9]*)?) ', res.stderr)
| if res.returncode != 0: | ||
| raise Exception(f"kotlinc -version failed: {res.stderr}") | ||
| m = re.match(r'.* kotlinc-jvm ([0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z][a-zA-Z0-9]*)?) .*', res.stderr) | ||
| m = re.search(r' kotlinc-jvm ([0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z][a-zA-Z0-9]*)?) ', res.stderr) |
There was a problem hiding this comment.
Improve the regex to use word boundaries and flexible whitespace, e.g. r"\bkotlinc-jvm\s+([0-9]+\.[0-9]+\.[0-9]+(?:-[A-Za-z][A-Za-z0-9]*)?)\b", to make it more robust against punctuation or line breaks.
Suggested change
| m = re.search(r' kotlinc-jvm ([0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z][a-zA-Z0-9]*)?) ', res.stderr) | |
| m = re.search(r"\bkotlinc-jvm\s+([0-9]+\.[0-9]+\.[0-9]+(?:-[A-Za-z][A-Za-z0-9]*)?)\b", res.stderr) |
igfoo
approved these changes
Jun 24, 2025
Member
igfoo
left a comment
There was a problem hiding this comment.
I'm not sure if these warnings indicate that something else will break, but from the Kotlin side it looks fine.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR changes
pick-kotlin-version.pyto use re.search() instead of re.match(), so that it can better cope with warning messages.Running
pick-kotlin-version.pywith JRE 24, without this PR:Running
pick-kotlin-version.pywith JRE 24, with this PR: