Skip to content

Commit 7517f7e

Browse files
authored
Merge pull request #47283 from Ladicek/jandex-auto-reindexing
Jandex: reindex if the index is too new
2 parents ec80b9b + 97572fa commit 7517f7e

4 files changed

Lines changed: 35 additions & 26 deletions

File tree

core/deployment/src/main/java/io/quarkus/deployment/index/IndexingUtil.java

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ public class IndexingUtil {
4444

4545
private static final int JAVA_VERSION;
4646

47-
// At least Jandex 2.1 is needed
48-
private static final int REQUIRED_INDEX_VERSION = 8;
47+
// At least Jandex 3.0 is needed
48+
private static final int REQUIRED_INDEX_VERSION = 11;
4949

5050
static {
5151
int version = 8;
@@ -71,7 +71,7 @@ public static Index indexJar(Path path, Set<String> removed) throws IOException
7171

7272
public static Index indexTree(OpenPathTree tree, Set<String> removed) throws IOException {
7373
if (removed == null) {
74-
final Index i = tree.apply(JANDEX_INDEX, MetaInfJandexReader.getInstance());
74+
final Index i = tree.apply(JANDEX_INDEX, new MetaInfJandexReader(tree.toString()));
7575
if (i != null) {
7676
return i;
7777
}
@@ -88,17 +88,19 @@ public static Index indexJar(File file, Set<String> removed) throws IOException
8888
if (existing != null && removed == null) {
8989
try (InputStream in = jarFile.getInputStream(existing)) {
9090
IndexReader reader = new IndexReader(in);
91-
if (reader.getIndexVersion() < REQUIRED_INDEX_VERSION) {
92-
log.warnf(
93-
"Re-indexing %s - at least Jandex 2.1 must be used to index an application dependency",
94-
file);
95-
return indexJar(jarFile, removed);
96-
} else {
97-
try {
98-
return reader.read();
99-
} catch (UnsupportedVersion e) {
100-
throw new UnsupportedVersion("Can't read Jandex index from " + file + ": " + e.getMessage());
91+
try {
92+
int indexVersion = reader.getIndexVersion();
93+
if (indexVersion < REQUIRED_INDEX_VERSION) {
94+
log.warnf("Reindexing %s, at least Jandex 3.0 must be used"
95+
+ " to index an application dependency (index version is %s)", file, indexVersion);
96+
return indexJar(jarFile, removed);
10197
}
98+
return reader.read();
99+
} catch (UnsupportedVersion e) {
100+
log.warnf("Reindexing %s, the index format is too new for the Jandex version"
101+
+ " used by your application. Please report it to the author of this JAR (%s)",
102+
file, e.getMessage());
103+
return indexJar(jarFile, removed);
102104
}
103105
}
104106
}
@@ -273,10 +275,10 @@ public void visitPath(PathVisit visit) {
273275
}
274276

275277
private static class MetaInfJandexReader implements Function<PathVisit, Index> {
276-
private static MetaInfJandexReader instance;
278+
private final String treeDescription;
277279

278-
private static MetaInfJandexReader getInstance() {
279-
return instance == null ? instance = new MetaInfJandexReader() : instance;
280+
MetaInfJandexReader(String treeDescription) {
281+
this.treeDescription = treeDescription;
280282
}
281283

282284
@Override
@@ -287,19 +289,22 @@ public Index apply(PathVisit visit) {
287289
try (InputStream in = Files.newInputStream(visit.getPath())) {
288290
IndexReader reader = new IndexReader(in);
289291
try {
290-
if (reader.getIndexVersion() < REQUIRED_INDEX_VERSION) {
291-
log.warnf(
292-
"Re-indexing %s:%s - at least Jandex 2.1 must be used to index an application dependency",
293-
visit.getRoot(), visit.getPath());
292+
int indexVersion = reader.getIndexVersion();
293+
if (indexVersion < REQUIRED_INDEX_VERSION) {
294+
log.warnf("Reindexing %s, at least Jandex 3.0 must be used"
295+
+ " to index an application dependency (index version is %s)",
296+
treeDescription, indexVersion);
294297
return null;
295298
}
296299
return reader.read();
297300
} catch (UnsupportedVersion e) {
298-
throw new UnsupportedVersion(
299-
"Can't read Jandex index from " + visit.getRoot() + ":" + visit.getPath() + ": " + e.getMessage());
301+
log.warnf("Reindexing %s, the index format is too new for the Jandex version"
302+
+ " used by your application. Please report it to the author of this JAR (%s)",
303+
treeDescription, e.getMessage());
304+
return null;
300305
}
301306
} catch (IOException e) {
302-
throw new UncheckedIOException("Can't read Jandex index from " + visit.getRoot() + ":" + visit.getPath(), e);
307+
throw new UncheckedIOException("Can't read Jandex index from " + treeDescription, e);
303308
}
304309
}
305310
}

extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/boot/StaticInitFailureTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ public class StaticInitFailureTest {
2727
.addClass(EntityWithIncorrectMapping.class))
2828
.withConfigurationResource("application.properties")
2929
// Expect only one error: the one we triggered
30-
.setLogRecordPredicate(record -> record.getLevel().intValue() >= Level.WARNING.intValue())
30+
.setLogRecordPredicate(record -> record.getLevel().intValue() >= Level.WARNING.intValue()
31+
// Ignore these particular warnings: they are not relevant to this test.
32+
&& !record.getMessage().contains("must be used to index an application dependency")) // too old Jandex
3133
// In particular we don't want a log telling us JPAConfig could not be created
3234
// because HibernateOrmRuntimeConfig is not initialized yet.
3335
// JPAConfig should not be created in the first place!

extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/config/dialect/DbVersionExtraSpaceTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ public class DbVersionExtraSpaceTest {
3737
// Ignore these particular warnings: they are not relevant to this test.
3838
&& !record.getMessage().contains("has been blocked for") //sometimes CI has a super slow moment and this triggers the blocked thread detector
3939
&& !record.getMessage().contains("Agroal")
40-
&& !record.getMessage().contains("Netty DefaultChannelId initialization"))
40+
&& !record.getMessage().contains("Netty DefaultChannelId initialization")
41+
&& !record.getMessage().contains("must be used to index an application dependency")) // too old Jandex
4142
.assertLogRecords(records -> assertThat(records)
4243
.extracting(LogRecord::getMessage) // This is just to get meaningful error messages, as LogRecord doesn't have a toString()
4344
.isEmpty());

extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/transaction/AbstractTransactionLifecycleTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ public abstract class AbstractTransactionLifecycleTest {
4949
&& !record.getMessage().contains("has been blocked for") //sometimes CI has a super slow moment and this triggers the blocked thread detector
5050
&& !record.getMessage().contains("Using Java versions older than 11 to build Quarkus applications")
5151
&& !record.getMessage().contains("Agroal does not support detecting if a connection is still usable")
52-
&& !record.getMessage().contains("Netty DefaultChannelId initialization"))
52+
&& !record.getMessage().contains("Netty DefaultChannelId initialization")
53+
&& !record.getMessage().contains("must be used to index an application dependency")) // too old Jandex
5354
.assertLogRecords(records -> assertThat(records)
5455
.extracting(LogRecord::getMessage) // This is just to get meaningful error messages, as LogRecord doesn't have a toString()
5556
.isEmpty());

0 commit comments

Comments
 (0)