Skip to content

Commit

Permalink
Merge pull request #136 from Ladicek/compatibility-promise
Browse files Browse the repository at this point in the history
Introduce a compatibility promise
  • Loading branch information
Ladicek authored Sep 2, 2021
2 parents 5ce7c08 + 2c2449a commit 7ebb6d3
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,26 @@ The above code prints the following output:
Target type:@Label(value = "Name") java.lang.String
Equivalent? true
```

## Compatibility Promise

Jandex uses an `X.Y.Z` versioning scheme.
In the following text, we call `X` a _major_ version, `Y` a _minor_ version, and `Z` a _micro_ version.

### API

Jandex may break backward compatibility for _callers_ of the Jandex API in major versions.
If you only call Jandex API, updating to a newer minor or micro version is safe.

Jandex may break backward compatibility for users that _extend_ Jandex classes or _implement_ Jandex interfaces in minor or major versions.
If you extend Jandex classes or implement Jandex interfaces, updating to a newer micro version is safe.

### Persistent Index Format

The persistent index format is versioned.
Jandex is backward compatible when it comes to reading the persistent index, but not forward compatible.
In other words, newer Jandex can read older index, but older Jandex can't read newer index.
Jandex may introduce a new persistent index format version in minor or major versions.
If you distribute a Jandex index as part of your artifacts, updating to a newer micro version is safe.
Updating to a newer minor or major version may require consumers of the Jandex index to also update.
5 changes: 4 additions & 1 deletion src/main/java/org/jboss/jandex/IndexReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ private void initReader(int version) throws IOException {
reader = new IndexReaderV2(input);
} else {
input.close();
throw new UnsupportedVersion("Version: " + version);
throw new UnsupportedVersion("Can't read index version " + version
+ "; this IndexReader only supports index versions "
+ IndexReaderV1.MIN_VERSION + "-" + IndexReaderV1.MAX_VERSION + ","
+ IndexReaderV2.MIN_VERSION + "-" + IndexReaderV2.MAX_VERSION);
}

this.reader = reader;
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/org/jboss/jandex/IndexWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ public int write(Index index, int version) throws IOException {

IndexWriterImpl writer = getWriter(version);
if (writer == null) {
throw new UnsupportedVersion("Version: " + version);
throw new UnsupportedVersion("Can't write index version " + version
+ "; this IndexWriter only supports index versions "
+ IndexWriterV1.MIN_VERSION + "-" + IndexWriterV1.MAX_VERSION + ","
+ IndexWriterV2.MIN_VERSION + "-" + IndexWriterV2.MAX_VERSION);
}

return writer.write(index, version);
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/jboss/jandex/IndexWriterV1.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ final class IndexWriterV1 extends IndexWriterImpl {
int write(Index index, int version) throws IOException {

if (version < MIN_VERSION || version > MAX_VERSION) {
throw new UnsupportedVersion("Version: " + version);
throw new UnsupportedVersion("Can't write index version " + version
+ "; this IndexWriterV1 only supports index versions "
+ IndexWriterV1.MIN_VERSION + "-" + IndexWriterV1.MAX_VERSION);
}

PackedDataOutputStream stream = new PackedDataOutputStream(new BufferedOutputStream(out));
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/jboss/jandex/IndexWriterV2.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ int size() {
int write(Index index, int version) throws IOException {

if (version < MIN_VERSION || version > MAX_VERSION) {
throw new UnsupportedVersion("Version: " + version);
throw new UnsupportedVersion("Can't write index version " + version
+ "; this IndexWriterV2 only supports index versions "
+ IndexWriterV2.MIN_VERSION + "-" + IndexWriterV2.MAX_VERSION);
}

PackedDataOutputStream stream = new PackedDataOutputStream(new BufferedOutputStream(out));
Expand Down

0 comments on commit 7ebb6d3

Please sign in to comment.