Skip to content

Conversation

@Gautam-aman
Copy link

Summary

This PR fixes the issue where the update check incorrectly reports an older version as a newer one. For example, it reported 3.4.6 as newer even when the currently used version was 3.5.0.

Root Cause

Version strings were compared lexicographically instead of numerically (e.g., "3.10" < "3.9" when using string comparison).

Fix

  • Implemented numeric comparison for version segments.
  • Treated shorter version strings (3.5) as equivalent to 3.5.0.
  • Added comprehensive unit test testCompareVersions() to prevent regressions.

Tests

All tests pass:
./gradlew :jib-plugins-common:test
./gradlew :jib-maven-plugin:test

This resolves the incorrect user warning which caused confusion as 3.4.6 is older than 3.5.0.

Notes

No behavior changes other than correcting version comparison.

@google-cla
Copy link

google-cla bot commented Dec 7, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Gautam-aman, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical bug in the update checker that caused it to misidentify older versions as newer, resulting in erroneous update prompts. The change introduces a sophisticated numeric version comparison mechanism, ensuring that update notifications are accurate and only triggered for genuinely newer versions. This enhancement improves the reliability of the update checker without altering any other system behaviors.

Highlights

  • Fixes Incorrect Update Reporting: The pull request resolves an issue where the update checker would incorrectly report an older version as a newer one, leading to misleading update notifications.
  • Numeric Version Comparison: The core of the fix involves replacing lexicographical string comparison of version numbers with a robust numeric comparison logic. This correctly handles cases like '3.10' being greater than '3.9'.
  • Handles Shorter Version Strings: The new comparison logic correctly treats shorter version strings (e.g., '3.5') as equivalent to their longer counterparts (e.g., '3.5.0') for accurate comparison.
  • Comprehensive Unit Tests: A new unit test, testCompareVersions(), has been added to validate the new version comparison logic against various scenarios, ensuring the fix is robust and prevents future regressions.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request fixes a version comparison bug by implementing a numeric comparison for version strings. The overall approach is good, and the addition of unit tests is appreciated.

I have two main points of feedback:

  1. The new version comparison logic does not handle pre-release suffixes (like -SNAPSHOT or -alpha) correctly, which can lead to missed update notifications. I've left a comment with more details and suggestions.
  2. There's a performance improvement opportunity in the parsePart method by avoiding repeated regex compilation. I've provided a code suggestion for this.

Addressing these points will make the update checker more robust and performant.

Comment on lines 66 to 79
static int compareVersions(String v1, String v2) {
String[] p1 = v1.split("\\.");
String[] p2 = v2.split("\\.");

int len = Math.max(p1.length, p2.length);
for (int i = 0; i < len; i++) {
int a = i < p1.length ? parsePart(p1[i]) : 0;
int b = i < p2.length ? parsePart(p2[i]) : 0;
if (a != b) {
return Integer.compare(a, b);
}
}
return 0;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The current implementation correctly handles numeric version parts but does not correctly handle pre-release identifiers like -alpha or -SNAPSHOT. For example, 1.0.0-SNAPSHOT should be considered an older version than 1.0.0, but this implementation will treat them as equal. This could lead to missed update notifications for users on pre-release versions.

I recommend adding test cases to cover these scenarios, for example:

assertThat(UpdateChecker.compareVersions("1.0.0-SNAPSHOT", "1.0.0")).isLessThan(0);
assertThat(UpdateChecker.compareVersions("1.0.0-alpha", "1.0.0-beta")).isLessThan(0);

To support this, the compareVersions method would need to be updated to handle these suffixes. One approach is to check for a hyphen in version parts. If the numeric parts are equal, the version part with a suffix can be considered smaller than one without. If both have suffixes, they can be compared lexicographically.

Comment on lines 81 to 89
private static int parsePart(String s) {
try {
// Extract leading numeric portion (e.g., "1-SNAPSHOT" → "1")
String digits = s.replaceAll("^(\\d+).*$", "$1");
return Integer.parseInt(digits);
} catch (NumberFormatException e) {
return 0;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using String.replaceAll() with a regex can be inefficient, as it typically compiles the regular expression on each call. Since this method is called within a loop in compareVersions, this could have a performance impact. A more performant approach would be to parse the leading digits manually. This also makes the logic for extracting the numeric part more explicit.

  private static int parsePart(String s) {
    // Extract leading numeric portion (e.g., "1-SNAPSHOT" → "1")
    int i = 0;
    while (i < s.length() && Character.isDigit(s.charAt(i))) {
      i++;
    }
    if (i == 0) {
      return 0;
    }
    try {
      return Integer.parseInt(s.substring(0, i));
    } catch (NumberFormatException e) {
      // Should only happen on integer overflow for very long version parts.
      return 0;
    }
  }

@Gautam-aman
Copy link
Author

Thanks for the helpful review! 🙌
I've updated the PR to:

  • Handle prerelease suffixes such as -SNAPSHOT, -alpha, -beta
  • Add test coverage for these cases
  • Switch to a manual numeric-prefix parser to avoid regex overhead

Please let me know if you'd like any further improvements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant