Ensure version starts with 'v' in VersionChecker#704
Conversation
This fixes a bug with version checker, since currently it fed strings of the form '1.2.3' and compares them against strings of the form 'v1.2.3' which always results in a mismatch.
There was a problem hiding this comment.
Code Review
This pull request updates the VersionChecker constructor to ensure the version string is prefixed with 'v' if it is not already. Feedback on these changes highlights a potential NullPointerException if the version parameter is null, and points out that modifying the static field CURRENT_VERSION within an instance constructor is a code smell that could lead to race conditions.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| if (version.startsWith("v")) { | ||
| CURRENT_VERSION = version; | ||
| } else { | ||
| CURRENT_VERSION = "v" + version; | ||
| } |
There was a problem hiding this comment.
There are two issues here:
- Potential NullPointerException: If the
versionparameter isnull, callingversion.startsWith("v")will throw aNullPointerException. - Static Field Modification: Modifying the static field
CURRENT_VERSIONfrom an instance constructor is a code smell and can lead to race conditions if multiple instances ofVersionCheckerare created. Ideally,CURRENT_VERSIONshould be an instance field (non-static), but at a minimum, we should guard againstnullvalues here.
if (version == null) {
CURRENT_VERSION = "v1.0";
} else if (version.startsWith("v")) {
CURRENT_VERSION = version;
} else {
CURRENT_VERSION = "v" + version;
}
This fixes a bug with version checker, since currently it fed strings of the form '1.2.3' and compares them against strings of the form 'v1.2.3' which always results in a mismatch.
Description
Please explain the changes you made here.
Checklist