You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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:
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, theequals()
method should be used.The text was updated successfully, but these errors were encountered: