smallrye / jandex

Java Annotation Indexer
Apache License 2.0
398 stars 94 forks source link

NegativeArraySizeException while scanning groovy-3.0.13.jar #279

Closed papegaaij closed 2 years ago

papegaaij commented 2 years ago

Since WildFly 27.0.0.Beta1, we are getting the following java.lang.NegativeArraySizeException when deploying our application in test mode (I've patched jandex to version 3.0.2):

2022-11-08 19:21:58,416 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-8) WFLYSRV0003: Could not index class org/codehaus/groovy/transform/tailrec/VariableReplacedListener$1.class at /content/keyhub-ear.ear/lib/arquillian-spock.jar: java.lang.NegativeArraySizeException: -1
        at io.smallrye.jandex//org.jboss.jandex.Indexer.adjustMethodParameters(Indexer.java:914)
        at io.smallrye.jandex//org.jboss.jandex.Indexer.indexWithSummary(Indexer.java:2322)
        at io.smallrye.jandex//org.jboss.jandex.Indexer.index(Indexer.java:2277)
        at org.jboss.as.server@19.0.0.Beta18//org.jboss.as.server.deployment.annotation.ResourceRootIndexer.indexResourceRoot(ResourceRootIndexer.java:99)
        at org.jboss.as.server@19.0.0.Beta18//org.jboss.as.server.deployment.annotation.AnnotationIndexProcessor.deploy(AnnotationIndexProcessor.java:51)
        at org.jboss.as.server@19.0.0.Beta18//org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:182)
        at org.jboss.msc@1.4.13.Final//org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1739)
        at org.jboss.msc@1.4.13.Final//org.jboss.msc.service.ServiceControllerImpl$StartTask.execute(ServiceControllerImpl.java:1701)
        at org.jboss.msc@1.4.13.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(Unknown Source)

The class it is failing on is from groovy-3.0.13.jar and I've confirmed that this bug is still present in main and can be reproduced with:

papegaaij@papegaaij:~/tmp/jandex (main u=)$ java -jar core/target/jandex-3.0.3-SNAPSHOT.jar ~/.m2/repository/org/codehaus/groovy/groovy/3.0.13/groovy-3.0.13.jar
ERROR: Could not index org/codehaus/groovy/transform/tailrec/VariableReplacedListener$1.class: -1
java.lang.NullPointerException: Cannot read the array length because "<local4>" is null
        at org.jboss.jandex.Indexer.propagateTypeVariables(Indexer.java:2740)
        at org.jboss.jandex.Indexer.complete(Indexer.java:2378)
        at org.jboss.jandex.JarIndexer.createJarIndex(JarIndexer.java:196)
        at org.jboss.jandex.JarIndexer.createJarIndex(JarIndexer.java:88)
        at org.jboss.jandex.Main.getIndex(Main.java:88)
        at org.jboss.jandex.Main.execute(Main.java:68)
        at org.jboss.jandex.Main.main(Main.java:53)

Bisection pointed to this commmit: 58de83149feb6d0709629628f64ce70d80d288ac. I hope this helps in tracking this down.

Ladicek commented 2 years ago

The Groovy compiler emits interesting bytecode. The VariableReplacedListener$1 class looks like an inner class (that is, non-static member class), but its constructor doesn't accept an instance of the enclosing class. I guess that's perfectly legal from JVMS perspective -- Jandex probably has too much assumptions about how inner classes look, based on the JLS. Fortunately, it should be straightforward to relax that assumption.