Skip to content

fix(sorting): use natural version ordering instead of lexicographic#3791

Open
himanshu07gupta wants to merge 1 commit intoeclipse-sw360:mainfrom
himanshu07gupta:fix/keycloak-error-messages
Open

fix(sorting): use natural version ordering instead of lexicographic#3791
himanshu07gupta wants to merge 1 commit intoeclipse-sw360:mainfrom
himanshu07gupta:fix/keycloak-error-messages

Conversation

@himanshu07gupta
Copy link

@himanshu07gupta himanshu07gupta commented Mar 3, 2026

Overview: Solving two sorting issue mentioned in #206, #236. The current version sorting uses String.CASE_INSENSITIVE_ORDER (lexicographic ordering) which produces incorrect results:

  1. 15.0 sorts before 2.0 because character '1' < '2'
  2. 1.1 SR1 sorts before 1.1 due to space/bracket character comparison

This PR introduces a NaturalVersionComparator that splits version strings into numeric and non-numeric segments, comparing numeric parts as integers instead of strings.

Before (broken): 1.0, 1.1, 1.1 SR1, 10.0, 15.0, 2.0, 3.0
After (fixed): 1.0, 1.1, 1.1 SR1, 2.0, 3.0, 10.0, 15.0

  • Did you add or update any new dependencies that are required for your change? - NO

Issue: #206, #236
Fixes #206
Fixes #236

Suggest Reviewer

@GMishx @mcjaeger Could you please review or assign someone to this pr? Please let me know if any edge case is missing.

How To Test?

Screen.Recording.2026-03-03.at.10.43.51.PM.1.mov
  1. Create a component with releases having versions: 15.0, 2.0, 1.0, 10.0, 3.0, 1.1, 1.1 SR1
  2. Create a project and link those releases
  3. Call GET /resource/api/projects/{projectId}/releases?sort=version,asc
  4. Verify order: 1.0, 1.1, 1.1 SR1, 2.0, 3.0, 10.0, 15.0

Have you implemented any additional tests? - Yes. Created a test file - libraries/datahandler/src/test/java/org/eclipse/sw360/datahandler/common/NaturalVersionComparatorTest.java

Checklist

Must:

  • All related issues are referenced in commit messages and in PR

@himanshu07gupta himanshu07gupta force-pushed the fix/keycloak-error-messages branch 2 times, most recently from 47ab944 to 0d9b7a9 Compare March 3, 2026 18:41
Replace lexicographic String.CASE_INSENSITIVE_ORDER with a new
NaturalVersionComparator for version string sorting. Lexicographic
ordering incorrectly places "15.0" before "2.0" because character
'1' < '2', and "1.1 SR1" before "1.1" due to space/bracket
comparison.

The new comparator splits version strings into numeric and
non-numeric segments, comparing numeric parts as integers.
This produces the correct order: 1.0, 1.1, 1.1 SR1, 2.0, 15.0.

Fixes eclipse-sw360#206
Fixes eclipse-sw360#236

Signed-off-by: Himanshu Gupta <himanshu07gupta@gmail.com>
Signed-off-by: himanshu07gupta <himanshu29gupta0703@gmail.com>
@himanshu07gupta himanshu07gupta force-pushed the fix/keycloak-error-messages branch from 0d9b7a9 to 31c3b5d Compare March 3, 2026 19:02
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.

Project sorting by versions is weird because of brackets around sorting of releases by versions incorrect / not optimal at two locations

1 participant