Skip to content
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

Relocation throwing ArrayIndexOutOfBoundsException from ASM with Gradle 4.0 #303

Closed
baron1405 opened this issue Jun 17, 2017 · 11 comments
Closed
Labels
Milestone

Comments

@baron1405
Copy link
Contributor

Hi John, hope you might give me some insights into what to try next. I have a project using the shadow plugin that has worked fine under Gradle 3.* using shadow 1.2.4. When I upgraded to Gradle 4.0 and shadow 2.0.0 the relocate calls throws an ArrayIndexOutOfBoundsException with an ASM related stack trace:

java.lang.ArrayIndexOutOfBoundsException: -1
        at shadow.org.objectweb.asm.Frame.a(Unknown Source)
        at shadow.org.objectweb.asm.CurrentFrame.a(Unknown Source)
        at shadow.org.objectweb.asm.MethodWriter.visitVarInsn(Unknown Source)
        at shadow.org.objectweb.asm.ClassReader.a(Unknown Source)
        at shadow.org.objectweb.asm.ClassReader.b(Unknown Source)
        at shadow.org.objectweb.asm.ClassReader.accept(Unknown Source)
        at shadow.org.objectweb.asm.ClassReader.accept(Unknown Source)
        at shadow.org.objectweb.asm.ClassWriter.toByteArray(Unknown Source)
        at shadow.org.objectweb.asm.ClassWriter$toByteArray.call(Unknown Source)
        at com.github.jengelman.gradle.plugins.shadow.tasks.ShadowCopyAction$StreamAction.remapClass(ShadowCopyAction.groovy:279)
        at com.github.jengelman.gradle.plugins.shadow.tasks.ShadowCopyAction$StreamAction.remapClass(ShadowCopyAction.groovy:250)
        at com.github.jengelman.gradle.plugins.shadow.tasks.ShadowCopyAction$StreamAction.visitArchiveFile(ShadowCopyAction.groovy:230)
        at com.github.jengelman.gradle.plugins.shadow.tasks.ShadowCopyAction$StreamAction$_processArchive_closure3.doCall(ShadowCopyAction.groovy:209)
        at com.github.jengelman.gradle.plugins.shadow.tasks.ShadowCopyAction$StreamAction.processArchive(ShadowCopyAction.groovy:207)
        at com.github.jengelman.gradle.plugins.shadow.tasks.ShadowCopyAction$StreamAction.visitFile(ShadowCopyAction.groovy:193)
        at com.github.jengelman.gradle.plugins.shadow.tasks.ShadowCopyAction$StreamAction.processFile(ShadowCopyAction.groovy:157)
        at org.gradle.api.internal.file.copy.NormalizingCopyActionDecorator$1$1.processFile(NormalizingCopyActionDecorator.java:66)
        at org.gradle.api.internal.file.copy.DuplicateHandlingCopyActionDecorator$1$1.processFile(DuplicateHandlingCopyActionDecorator.java:60)
        at org.gradle.api.internal.file.copy.CopyFileVisitorImpl.processFile(CopyFileVisitorImpl.java:62)
        at org.gradle.api.internal.file.copy.CopyFileVisitorImpl.visitFile(CopyFileVisitorImpl.java:46)
        at org.gradle.api.internal.file.AbstractFileTree$FilteredFileTreeImpl$1.visitFile(AbstractFileTree.java:181)
        at org.gradle.api.internal.file.collections.SingletonFileTree.visit(SingletonFileTree.java:42)
        at org.gradle.api.internal.file.collections.FileTreeAdapter.visit(FileTreeAdapter.java:110)
        at org.gradle.api.internal.file.AbstractFileTree$FilteredFileTreeImpl.visit(AbstractFileTree.java:172)
        at org.gradle.api.internal.file.CompositeFileTree.visit(CompositeFileTree.java:87)
        at org.gradle.api.internal.file.copy.CopySpecActionImpl.execute(CopySpecActionImpl.java:39)
        at org.gradle.api.internal.file.copy.CopySpecActionImpl.execute(CopySpecActionImpl.java:24)
        at org.gradle.api.internal.file.copy.DefaultCopySpec$DefaultCopySpecResolver.walk(DefaultCopySpec.java:648)
        at org.gradle.api.internal.file.copy.DefaultCopySpec$DefaultCopySpecResolver.walk(DefaultCopySpec.java:650)
        at org.gradle.api.internal.file.copy.DefaultCopySpec.walk(DefaultCopySpec.java:458)
        at org.gradle.api.internal.file.copy.CopySpecBackedCopyActionProcessingStream.process(CopySpecBackedCopyActionProcessingStream.java:38)
        at org.gradle.api.internal.file.copy.DuplicateHandlingCopyActionDecorator$1.process(DuplicateHandlingCopyActionDecorator.java:44)
        at org.gradle.api.internal.file.copy.NormalizingCopyActionDecorator$1.process(NormalizingCopyActionDecorator.java:57)
        at org.gradle.api.internal.file.copy.CopyActionProcessingStream$process.call(Unknown Source)
        at com.github.jengelman.gradle.plugins.shadow.tasks.ShadowCopyAction$1.execute(ShadowCopyAction.groovy:81)
        at com.github.jengelman.gradle.plugins.shadow.tasks.ShadowCopyAction$1$execute.call(Unknown Source)
        at com.github.jengelman.gradle.plugins.shadow.tasks.ShadowCopyAction.withResource(ShadowCopyAction.groovy:112)
        at com.github.jengelman.gradle.plugins.shadow.tasks.ShadowCopyAction.execute(ShadowCopyAction.groovy:78)
        at org.gradle.api.internal.file.copy.NormalizingCopyActionDecorator.execute(NormalizingCopyActionDecorator.java:53)
        at org.gradle.api.internal.file.copy.DuplicateHandlingCopyActionDecorator.execute(DuplicateHandlingCopyActionDecorator.java:42)
        at org.gradle.api.internal.file.copy.CopyActionExecuter.execute(CopyActionExecuter.java:40)
        at org.gradle.api.tasks.AbstractCopyTask.copy(AbstractCopyTask.java:174)
        at com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar.copy(ShadowJar.java:72)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
        at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.doExecute(DefaultTaskClassInfoStore.java:141)
        at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:134)
        at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:121)
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:711)
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:694)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:122)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:317)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:309)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:185)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:95)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:111)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
        at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88)
        at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
        at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
        at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:242)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:317)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:309)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:185)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:95)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:235)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:224)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:121)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:77)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:102)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:96)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:612)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:567)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:96)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
        at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:46)
        at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)

I have verified that only the ASM 5.2 dependencies from shadow are present on the build classpath. Any thoughts on what to look at next would be appreciated.

Thanks,
Baron

@johnrengelman johnrengelman modified the milestones: 2.0.1, 2.0.2 Jun 23, 2017
@johnrengelman
Copy link
Collaborator

Do you have a sample project available to exhibits this problem?

@baron1405
Copy link
Contributor Author

Unfortunately, it is a rather large internal project.

@jaysudodeveloper
Copy link

No sure if related but im using this plugin with Jooby and when building this with shadow jar the gradle task runShadow does not work with gradle 4.0 and produces index out of bounds exception in my application, gist for reference.

However when i generate a gradlewrapper for version 3.5 and run gradlew installShadowApp and gradlew runShadow it works perfectly.

@hyangtack
Copy link

hyangtack commented Nov 3, 2017

Hello, @johnrengelman . I also got StringIndexOutOfBoundsException from shadow like as follows:

Caused by: org.gradle.api.GradleException: Error in ASM processing class com/linecorp/centraldogma/server/internal/admin/service/ProjectMetadataService.class
        at sun.reflect.GeneratedConstructorAccessor450.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83)
        at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:105)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:255)
        at com.github.jengelman.gradle.plugins.shadow.tasks.ShadowCopyAction$StreamAction.remapClass(ShadowCopyAction.groovy:276)
        at sun.reflect.GeneratedMethodAccessor1775.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:210)
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:59)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:182)
        at com.github.jengelman.gradle.plugins.shadow.tasks.ShadowCopyAction$StreamAction.remapClass(ShadowCopyAction.groovy:256)
        at sun.reflect.GeneratedMethodAccessor1783.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:210)
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:59)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:166)
        at com.github.jengelman.gradle.plugins.shadow.tasks.ShadowCopyAction$StreamAction.visitFile(ShadowCopyAction.groovy:186)
        ... 93 more
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: 2
        at java.lang.String.charAt(String.java:658)
        at shadow.org.objectweb.asm.signature.SignatureReader.a(Unknown Source)
        at shadow.org.objectweb.asm.signature.SignatureReader.acceptType(Unknown Source)
        at shadow.org.objectweb.asm.commons.Remapper.mapSignature(Unknown Source)
        at shadow.org.objectweb.asm.commons.MethodRemapper.visitLocalVariable(Unknown Source)
        at shadow.org.objectweb.asm.ClassReader.a(Unknown Source)
        at shadow.org.objectweb.asm.ClassReader.b(Unknown Source)
        at shadow.org.objectweb.asm.ClassReader.accept(Unknown Source)
        at shadow.org.objectweb.asm.ClassReader.accept(Unknown Source)
        at shadow.org.objectweb.asm.ClassReader$accept.call(Unknown Source)
        at com.github.jengelman.gradle.plugins.shadow.tasks.ShadowCopyAction$StreamAction.remapClass(ShadowCopyAction.groovy:274)
        ... 107 more

The exception is different from @baron1405 's but the stack trace is similar. I got this error after applying gradle-aspectj plugin to my project. If I don't apply it, everything is ok. Hope it helps.

Versions:

  • gradle 4.2
  • groovy 2.4.11
  • shadow 2.0.1
  • gradle-aspectj plugin 2.0
  • aspectjweaver & aspectjrt 1.8.12
  • java 1.8.0_144

@johnrengelman
Copy link
Collaborator

Can someone trying the 2.0.2-SNAPSHOT and see if this error goes away?

The snapshot repository is at http://oss.jfrog.org/artifactory/simple/oss-snapshot-local/

@hyangtack
Copy link

I tried but I got an error from gradle:

* What went wrong:
A problem occurred configuring root project 'centraldogma'.
> Could not resolve all files for configuration ':classpath'.
   > Could not resolve com.github.jengelman.gradle.plugins:shadow:2.0.2-SNAPSHOT.
     Required by:
         project :
      > Could not resolve com.github.jengelman.gradle.plugins:shadow:2.0.2-SNAPSHOT.
         > inconsistent module metadata found. Descriptor: com.github.jengelman.gradle.plugins:shadow:2.0.0 Errors: bad version: expected='2.0.2-SNAPSHOT' found='2.0.0'

The version is 2.0.0 in the following pom.
http://oss.jfrog.org/artifactory/simple/oss-snapshot-local/com/github/jengelman/gradle/plugins/shadow/2.0.2-SNAPSHOT/shadow-2.0.2-20171105.210241-1.pom

Please let me know if it's fixed.

@johnrengelman
Copy link
Collaborator

Ok, fixed that problem. Can you try again?

@hyangtack
Copy link

I tried but got a similar error. :-(
I want to make a small project to reproduce, but it's not easy to do for now.

Caused by: org.gradle.api.GradleException: Error in ASM processing class com/linecorp/centraldogma/server/internal/admin/service/ProjectMetadataService.class
        at com.github.jengelman.gradle.plugins.shadow.tasks.ShadowCopyAction$StreamAction.remapClass(ShadowCopyAction.groovy:279)
        at com.github.jengelman.gradle.plugins.shadow.tasks.ShadowCopyAction$StreamAction.remapClass(ShadowCopyAction.groovy:259)
        at com.github.jengelman.gradle.plugins.shadow.tasks.ShadowCopyAction$StreamAction.visitFile(ShadowCopyAction.groovy:189)
        ... 73 more
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: 2
        at shadow.org.objectweb.asm.signature.SignatureReader.parseType(SignatureReader.java:177)
        at shadow.org.objectweb.asm.signature.SignatureReader.acceptType(SignatureReader.java:130)
        at shadow.org.objectweb.asm.commons.Remapper.mapSignature(Remapper.java:164)
        at shadow.org.objectweb.asm.commons.MethodRemapper.visitLocalVariable(MethodRemapper.java:214)
        at shadow.org.objectweb.asm.ClassReader.readCode(ClassReader.java:1696)
        at shadow.org.objectweb.asm.ClassReader.readMethod(ClassReader.java:1126)
        at shadow.org.objectweb.asm.ClassReader.accept(ClassReader.java:698)
        at shadow.org.objectweb.asm.ClassReader.accept(ClassReader.java:500)
        at shadow.org.objectweb.asm.ClassReader$accept.call(Unknown Source)
        at com.github.jengelman.gradle.plugins.shadow.tasks.ShadowCopyAction$StreamAction.remapClass(ShadowCopyAction.groovy:277)
        ... 75 more

@johnrengelman
Copy link
Collaborator

All the tests I've run and examples people have given me are passing with ASM 6.0.
So, unless someone can give me a reproducible example (either a dependency + shadow configuration, or a link to a public project).

I'm even wiling to work offline with a private project if someone would like.

@johnrengelman
Copy link
Collaborator

@JayTheKing I'm not sure your issue is the same thing. I don't see any shadow or ASM classes in that stracktrace.

@johnrengelman
Copy link
Collaborator

2.0.2 is now available with this fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants