Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 266081 - [Version] More consistent handling of MIN/MAX versions in ranges
Summary: [Version] More consistent handling of MIN/MAX versions in ranges
Status: RESOLVED FIXED
Alias: None
Product: Equinox
Classification: Eclipse Project
Component: p2 (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.5 M6   Edit
Assignee: P2 Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-02-25 03:33 EST by Thomas Hallgren CLA
Modified: 2009-03-04 08:36 EST (History)
2 users (show)

See Also:


Attachments
Tests that provokes the problem (3.65 KB, patch)
2009-02-25 03:35 EST, Thomas Hallgren CLA
john.arthorne: iplog+
Details | Diff
Remedy for the problems (5.71 KB, patch)
2009-02-25 03:39 EST, Thomas Hallgren CLA
john.arthorne: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Hallgren CLA 2009-02-25 03:33:42 EST
We currently have some inconsistencies in how the MIN and MAX versions are handled in the VersionRange. Consider the following:

  VersionRange gtEqual = new VersionRange("format(n[.n=0;[.n=0;]][d?S=M;]):2.1");
  Version max = gtEqual.getMaximum();

The max version is now the Version.MAX_VERSION.

  Version max = new Version("format(n[.n=0;[.n=0;]][d?S=M;]):2.1");
  VersionRange lt = new VersionRange(null, true, max, false);
  Version min = lt.getMinimum();

The min version is now the Version.MIN_VERSION.

Problem 1.
A VersionRange can only have one format and by that definition, both the above ranges are incorrect since the Version.MIN_VERSION and Version.MAX_VERSION does not conform with the format of the version at the opposite end. As a result, the following code will sometimes result in an IllegalArgumentException.

VersionRange range = new VersionRange(someVersion, true, null, true);
Version min = range.getMinimum();
Version max = range.getMaximum();
VersionRange anotherRange = new VersionRange(min, true, max, true);

Problem 2.
The VersionRange.toString() uses the format of the minVersion on output.

Problem 3.
Since a MIN_VERSION and a MAX_VERSION are exposed as public constants, it would be good if they could be used when creating OSGi VersionRanges too, i.e. this should be legal:

VersionRange range = new VersionRange(new Version(1,0,0), true, Version.MAX_VERSION, true);

and result in the same thing as:

VersionRange range = new VersionRange(new Version(1,0,0), true, null, true);

(the implementation must automatically substitute the Version.MAX_VERSION for the OSGi max version to retain backward compatibility).
Comment 1 Thomas Hallgren CLA 2009-02-25 03:35:01 EST
Created attachment 126683 [details]
Tests that provokes the problem

Some additional tests for the omniversion test suite that provokes the MIN/MAX inconsistencies.
Comment 2 Thomas Hallgren CLA 2009-02-25 03:39:29 EST
Created attachment 126685 [details]
Remedy for the problems

This patch will fix the problems:

1. A VersionRange can have differnet formats on its versions provided that one of the versions is the Version.MIN_VERSION or the Version.MAX_VERSION

2. The Version format of the VersionRange is obtained from the lower bound by default but if it's found to be the MIN_VERSION, the upper bound format is used instead.

3. If a range is created with a combination of an OSGi Version and the MIN_VERSION or MAX_VERSION, this is now allowed but the MIN_VERSION/MAX_VERSION will be replaced with its correspondence OSGi equivalent.
Comment 3 John Arthorne CLA 2009-03-03 23:51:44 EST
Released in HEAD. Changing VersionFormat#parseRaw to package private didn't seem related to the bug. I assume that change was intentional?
Comment 4 Thomas Hallgren CLA 2009-03-04 08:36:40 EST
(In reply to comment #3)
> Released in HEAD. Changing VersionFormat#parseRaw to package private didn't
> seem related to the bug. I assume that change was intentional?
> 
Yes it was. I discovered that leaving it public was unnecessary and could potentially lead to the creation of bogus versions.