smallrye / jandex

Java Annotation Indexer

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Indexing Exception with Google Guava 31.0

codylerum opened this issue · comments

After updating the guava version in my war from 30.0.1 to 31.0 I'm getting a warning on deploy in Wildfly 24.0.1

15:27:23,515 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-3) WFLYSRV0003: Could not index class com/google/common/collect/AbstractSortedSetMultimap.class at /content/ROOT.war/WEB-INF/lib/guava-31.0-jre.jar: java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
    at org.jboss.jandex@2.2.3.Final//org.jboss.jandex.Indexer.updateTypeTarget(Indexer.java:903)
    at org.jboss.jandex@2.2.3.Final//org.jboss.jandex.Indexer.updateTypeTargets(Indexer.java:630)
    at org.jboss.jandex@2.2.3.Final//org.jboss.jandex.Indexer.index(Indexer.java:1698)
    at org.jboss.as.server@16.0.1.Final//org.jboss.as.server.deployment.annotation.ResourceRootIndexer.indexResourceRoot(ResourceRootIndexer.java:99)
    at org.jboss.as.server@16.0.1.Final//org.jboss.as.server.deployment.annotation.AnnotationIndexProcessor.deploy(AnnotationIndexProcessor.java:51)
    at org.jboss.as.server@16.0.1.Final//org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:182)
    at org.jboss.msc@1.4.12.Final//org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1739)
    at org.jboss.msc@1.4.12.Final//org.jboss.msc.service.ServiceControllerImpl$StartTask.execute(ServiceControllerImpl.java:1701)
    at org.jboss.msc@1.4.12.Final//org.jboss.msc.service.ServiceControllerImpl$ControllerTask.run(ServiceControllerImpl.java:1559)
    at org.jboss.threads@2.4.0.Final//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
    at org.jboss.threads@2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1990)
    at org.jboss.threads@2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
    at org.jboss.threads@2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
    at java.base/java.lang.Thread.run(Thread.java:831)

Getting the same message for

com/google/common/util/concurrent/AbstractListeningExecutorService.class
com/google/common/util/concurrent/ListeningScheduledExecutorService.class
com/google/common/util/concurrent/ListeningExecutorService.class
com/google/common/util/concurrent/ForwardingListeningExecutorService.class
com/google/common/util/concurrent/MoreExecutors$ScheduledListeningDecorator.class
com/google/common/collect/AbstractSortedSetMultimap.class
com/google/common/collect/MultimapBuilder$MultimapBuilderWithKeys$3.class
com/google/common/collect/MultimapBuilder$MultimapBuilderWithKeys$4.class
com/google/common/collect/MultimapBuilder$MultimapBuilderWithKeys$2.class
com/google/common/collect/MultimapBuilder$MultimapBuilderWithKeys$1.class

Might be related to Guava adding @nullable annotations into their type definitions like

protected final <T extends @Nullable Object> RunnableFuture<T> newTaskFor(Callable<T> callable) {

google/guava@4b02d3c#diff-5b544bc293bc6061a65179dcbe857b8b732d0d74679492e7679200aad6c7cf14R45

It fails also with Jandex 2.4.0.Final:

Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
	at org.jboss.jandex.Indexer.updateTypeTarget(Indexer.java:1120)
	at org.jboss.jandex.Indexer.updateTypeTargets(Indexer.java:842)
	at org.jboss.jandex.Indexer.index(Indexer.java:1970)
	at io.quarkus.deployment.index.IndexingUtil.indexJar(IndexingUtil.java:99)
	at io.quarkus.deployment.index.IndexingUtil.indexJar(IndexingUtil.java:68)
	at io.quarkus.deployment.index.IndexingUtil.indexJar(IndexingUtil.java:49)
	at io.quarkus.deployment.index.ApplicationArchiveBuildStep$1.apply(ApplicationArchiveBuildStep.java:287)
	at io.quarkus.deployment.index.ApplicationArchiveBuildStep$1.apply(ApplicationArchiveBuildStep.java:283)
	at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1133)
	at io.quarkus.deployment.index.ApplicationArchiveBuildStep.handleJarPath(ApplicationArchiveBuildStep.java:283)
	at io.quarkus.deployment.index.ApplicationArchiveBuildStep.indexPath(ApplicationArchiveBuildStep.java:192)
	at io.quarkus.deployment.index.ApplicationArchiveBuildStep.createApplicationArchive(ApplicationArchiveBuildStep.java:186)
	at io.quarkus.deployment.index.ApplicationArchiveBuildStep.addIndexDependencyPaths(ApplicationArchiveBuildStep.java:170)
	at io.quarkus.deployment.index.ApplicationArchiveBuildStep.scanForOtherIndexes(ApplicationArchiveBuildStep.java:129)
	at io.quarkus.deployment.index.ApplicationArchiveBuildStep.build(ApplicationArchiveBuildStep.java:103)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at io.quarkus.deployment.ExtensionLoader$2.execute(ExtensionLoader.java:820)
	at io.quarkus.builder.BuildContext.run(BuildContext.java:277)
	at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
	at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
	at java.base/java.lang.Thread.run(Thread.java:829)
	at org.jboss.threads.JBossThread.run(JBossThread.java:501)

Thanks for the report. This is probably a similar javac output problem to #93. I will take a look

Trying with com/google/common/collect/AbstractSortedSetMultimap.class, the problematic method is unmodifiableCollectionSubclass. It is present in the class file twice: "normal" method together with the signature attribute, and a bridge method without signature. I see comments in the code that this situation should be handled, but for some reason, it is not. Will keep digging.

FTR, here's a simple reproducer:

public class TypeAnnotationOnBridgeMethodTest {
    @Retention(RetentionPolicy.RUNTIME)
    @Target(ElementType.TYPE_USE)
    @interface MyAnnotation {
    }

    static class Foo {
        <E extends @MyAnnotation Object> Collection<E> method() {
            return null;
        }
    }

    static class Bar extends Foo {
        @Override
        <E extends @MyAnnotation Object> Set<E> method() {
            return null;
        }
    }

    @Test
    public void test() throws IOException {
        Index.of(Foo.class, Bar.class);
    }
}

I have a fix, but adding a test to the 2.4 branch will require a new release of the test data project (https://github.com/wildfly/typeannotation-test/). Unfortunately, I don't have permissions for that repository. I'll try to figure that out.

PRs are up for 3.0 (#153) and 2.4 (#154), but I need wildfly/typeannotation-test#2 merged and released first (for 2.4, that is).