Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Semver.isEquivalentTo() returns always false for larger major versions and SemverType.NPM #53

Open
oheger-bosch opened this issue Mar 8, 2021 · 1 comment

Comments

@oheger-bosch
Copy link

For my use case I have to deal with version numbers that use Calendar versioning. Such version numbers have the same structure as semantic version numbers, although the single components cannot be assigned to patch, minor, or major levels. Nevertheless, it should be possible to check whether such a version number is within a specific range.

I found out, however, that those checks always fail. I narrowed down the problem to a minimum failing test case:

Semver v1 = new Semver("2021.1.6", Semver.SemverType.NPM);
Semver v2 = new Semver("2021.1.6", Semver.SemverType.NPM);

assertTrue(v1.isEquivalentTo(v2));  // Fails

The cause for the problem seems to be in the isEqualTo() method. Here the major version numbers (which are Integer objects) are compared to using != (i.e. reference semantics). As the Integer instances will be different, the major versions are always considered as not equivalent.

The comparison works for smaller numbers because Integer.valueOf() has a cache for instances within a specific range. So in this range, the comparison of references yields correct results, but in general, the equals() method should be used.

@piotrooo
Copy link

@oheger-bosch if you are still interesting, I've made copy of this lib and fix bug reported by you. Look for version 2.0.1

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

No branches or pull requests

2 participants