-
Notifications
You must be signed in to change notification settings - Fork 94
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
Allow configuring persistent index format version in the Maven plugin #320
Conversation
Out of curiosity, is this something you actually need, or did you implement it just "for fun"? |
😃 In short the change did not help me to solve my original issue. We have a project where we use Jandex 1 or 2 (because of Hibernate depends on Jandex and Wildfly provide Jandex module). But once jandex-maven-plugin stopped working with latest JDK ea builds (5f044c1). I thought I could use latest jandex-maven-plugin 3 to create persistent index compatible with Jandex 2. But despite the fact that the versions of the formats have become the same, Jandex 2 could not read the index (unknown annotation tag value, if I remember it right)... Since there is the issue #137 (someone else need something like this) and I have already made changes, why not make a PR. |
OK, that is interesting. If you can provide a reproducer, I can take a look. In the meantime, I'll try to find some time to write a test for this and then merge. |
I was able to reproduce a problem (or maybe one case) with this example: import java.util.List;
public interface X<T extends List<T>> { } javac --release 11 X.java Test runner import org.jboss.jandex.Index;
import org.jboss.jandex.IndexReader;
import org.jboss.jandex.IndexWriter;
import org.jboss.jandex.Indexer;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
class Scratch {
public static void main(String[] args) throws IOException {
if (args.length > 0 && "create".equals(args[0])) {
Indexer indexer = new Indexer();
try (InputStream inputStream = Files.newInputStream(Paths.get("X.class"))) {
indexer.index(inputStream);
}
Index index = indexer.complete();
try (OutputStream outputStream = Files.newOutputStream(Paths.get("jandex.idx"))) {
IndexWriter indexWriter = new IndexWriter(outputStream);
indexWriter.write(index, 9);
}
} else {
try (InputStream inputStream = Files.newInputStream(Paths.get("jandex.idx"))) {
Index index = new IndexReader(inputStream).read();
System.out.println("index.getKnownClasses().size() = " + index.getKnownClasses().size());
}
}
}
} Create index with Jandex 3, version java -cp jandex-3.1.2.jar --source 11 scratch.java create Try to read index with Jandex 2: java -cp jandex-2.2.3.Final.jar --source 11 scratch.java Get error:
But this works fine: java -cp jandex-3.1.2.jar --source 11 scratch.java
|
I'll take a look. Apparently we broke compatibility, which is bad. Thanks for the reproducer! |
OK, the problem is that Jandex 3 added a new kind of types, type variable references, and the serialization code doesn't account for that when serializing to an older version. Fortunately, there's a simple fix -- what Jandex 3 represents as a type variable reference, Jandex 2 represented as an unresolved type variable, so we'll just resort to writing an unresolved type variable for older versions of the serialization format. Here's a PR: #324 If you could build Jandex from that branch and check, that would be great. It passes your reproducer above. |
Thanks, I'll try after the weekend. |
Yes, now it works on the whole project! Thanks! Wait for release... |
Resolves #137