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

Shading fails on Java17 with UnsupportedOperationException: PermittedSubclasses requires ASM9 #479

Closed
easel opened this issue Oct 14, 2022 · 9 comments

Comments

@easel
Copy link

easel commented Oct 14, 2022

It appears as if for shading to work on Java 17 some dependencies must be updated. Definitely asm, possibly jar jar links as well. For reference, here's a full stack trace trying to shade cats.** into a spark project on Java 17:

[error] java.io.IOException: Unable to transform org/elasticsearch/hadoop/util/unit/ByteSizeUnit.class
[error] 	at com.eed3si9n.jarjar.util.JarTransformer.process(JarTransformer.java:41)
[error] 	at com.eed3si9n.jarjar.util.JarProcessorChain.process(JarProcessorChain.java:38)
[error] 	at com.eed3si9n.jarjar.JJProcessor.process(JJProcessor.scala:108)
[error] 	at com.eed3si9n.jarjarabrams.Shader$.$anonfun$bytecodeShader$6(Shader.scala:75)
[error] 	at com.eed3si9n.jarjarabrams.Shader$.$anonfun$shadeDirectory$4(Shader.scala:21)
[error] 	at scala.collection.TraversableLike.$anonfun$flatMap$1(TraversableLike.scala:293)
[error] 	at scala.collection.Iterator.foreach(Iterator.scala:943)
[error] 	at scala.collection.Iterator.foreach$(Iterator.scala:943)
[error] 	at scala.collection.AbstractIterator.foreach(Iterator.scala:1431)
[error] 	at scala.collection.IterableLike.foreach(IterableLike.scala:74)
[error] 	at scala.collection.IterableLike.foreach$(IterableLike.scala:73)
[error] 	at scala.collection.AbstractIterable.foreach(Iterable.scala:56)
[error] 	at scala.collection.TraversableLike.flatMap(TraversableLike.scala:293)
[error] 	at scala.collection.TraversableLike.flatMap$(TraversableLike.scala:290)
[error] 	at scala.collection.AbstractTraversable.flatMap(Traversable.scala:108)
[error] 	at com.eed3si9n.jarjarabrams.Shader$.shadeDirectory(Shader.scala:17)
[error] 	at sbtassembly.Assembly$.$anonfun$assembleMappings$9(Assembly.scala:269)
[error] 	at scala.collection.parallel.AugmentedIterableIterator.map2combiner(RemainsIterator.scala:116)
[error] 	at scala.collection.parallel.AugmentedIterableIterator.map2combiner$(RemainsIterator.scala:113)
[error] 	at scala.collection.parallel.immutable.ParVector$ParVectorIterator.map2combiner(ParVector.scala:66)
[error] 	at scala.collection.parallel.ParIterableLike$Map.leaf(ParIterableLike.scala:1064)
[error] 	at scala.collection.parallel.Task.$anonfun$tryLeaf$1(Tasks.scala:53)
[error] 	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
[error] 	at scala.util.control.Breaks$$anon$1.catchBreak(Breaks.scala:67)
[error] 	at scala.collection.parallel.Task.tryLeaf(Tasks.scala:56)
[error] 	at scala.collection.parallel.Task.tryLeaf$(Tasks.scala:50)
[error] 	at scala.collection.parallel.ParIterableLike$Map.tryLeaf(ParIterableLike.scala:1061)
[error] 	at scala.collection.parallel.AdaptiveWorkStealingTasks$WrappedTask.compute(Tasks.scala:153)
[error] 	at scala.collection.parallel.AdaptiveWorkStealingTasks$WrappedTask.compute$(Tasks.scala:149)
[error] 	at scala.collection.parallel.AdaptiveWorkStealingForkJoinTasks$WrappedTask.compute(Tasks.scala:440)
[error] 	at java.base/java.util.concurrent.RecursiveAction.exec(RecursiveAction.java:194)
[error] 	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
[error] 	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
[error] 	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
[error] 	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
[error] 	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)
[error] Caused by: java.lang.UnsupportedOperationException: PermittedSubclasses requires ASM9
[error] 	at org.objectweb.asm.ClassVisitor.visitPermittedSubclass(ClassVisitor.java:266)
[error] 	at org.objectweb.asm.ClassVisitor.visitPermittedSubclass(ClassVisitor.java:269)
[error] 	at org.objectweb.asm.commons.ClassRemapper.visitPermittedSubclass(ClassRemapper.java:228)
[error] 	at org.objectweb.asm.ClassReader.accept(ClassReader.java:706)
[error] 	at org.objectweb.asm.ClassReader.accept(ClassReader.java:424)
[error] 	at com.eed3si9n.jarjar.util.JarTransformer.process(JarTransformer.java:39)
[error] 	at com.eed3si9n.jarjar.util.JarProcessorChain.process(JarProcessorChain.java:38)
[error] 	at com.eed3si9n.jarjar.JJProcessor.process(JJProcessor.scala:108)
[error] 	at com.eed3si9n.jarjarabrams.Shader$.$anonfun$bytecodeShader$6(Shader.scala:75)
[error] 	at com.eed3si9n.jarjarabrams.Shader$.$anonfun$shadeDirectory$4(Shader.scala:21)
[error] 	at scala.collection.TraversableLike.$anonfun$flatMap$1(TraversableLike.scala:293)
[error] 	at scala.collection.Iterator.foreach(Iterator.scala:943)
[error] 	at scala.collection.Iterator.foreach$(Iterator.scala:943)
[error] 	at scala.collection.AbstractIterator.foreach(Iterator.scala:1431)
[error] 	at scala.collection.IterableLike.foreach(IterableLike.scala:74)
[error] 	at scala.collection.IterableLike.foreach$(IterableLike.scala:73)
[error] 	at scala.collection.AbstractIterable.foreach(Iterable.scala:56)
[error] 	at scala.collection.TraversableLike.flatMap(TraversableLike.scala:293)
[error] 	at scala.collection.TraversableLike.flatMap$(TraversableLike.scala:290)
[error] 	at scala.collection.AbstractTraversable.flatMap(Traversable.scala:108)
[error] 	at com.eed3si9n.jarjarabrams.Shader$.shadeDirectory(Shader.scala:17)
[error] 	at sbtassembly.Assembly$.$anonfun$assembleMappings$9(Assembly.scala:269)
[error] 	at scala.collection.parallel.AugmentedIterableIterator.map2combiner(RemainsIterator.scala:116)
[error] 	at scala.collection.parallel.AugmentedIterableIterator.map2combiner$(RemainsIterator.scala:113)
[error] 	at scala.collection.parallel.immutable.ParVector$ParVectorIterator.map2combiner(ParVector.scala:66)
[error] 	at scala.collection.parallel.ParIterableLike$Map.leaf(ParIterableLike.scala:1064)
[error] 	at scala.collection.parallel.Task.$anonfun$tryLeaf$1(Tasks.scala:53)
[error] 	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
[error] 	at scala.util.control.Breaks$$anon$1.catchBreak(Breaks.scala:67)
[error] 	at scala.collection.parallel.Task.tryLeaf(Tasks.scala:56)
[error] 	at scala.collection.parallel.Task.tryLeaf$(Tasks.scala:50)
[error] 	at scala.collection.parallel.ParIterableLike$Map.tryLeaf(ParIterableLike.scala:1061)
[error] 	at scala.collection.parallel.AdaptiveWorkStealingTasks$WrappedTask.compute(Tasks.scala:153)
[error] 	at scala.collection.parallel.AdaptiveWorkStealingTasks$WrappedTask.compute$(Tasks.scala:149)
[error] 	at scala.collection.parallel.AdaptiveWorkStealingForkJoinTasks$WrappedTask.compute(Tasks.scala:440)
[error] 	at java.base/java.util.concurrent.RecursiveAction.exec(RecursiveAction.java:194)
[error] 	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
[error] 	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
[error] 	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
[error] 	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
[error] 	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)
@MichaelBaker
Copy link

Is there a fix or workaround for this? I'm also getting this error with Java 17.

@eed3si9n
Copy link
Member

eed3si9n commented Jun 7, 2023

I guess I need to bump ASM here https://github.com/eed3si9n/jarjar-abrams/blob/develop/build.sbt#L26-L27

@Kyo91
Copy link

Kyo91 commented Jun 7, 2023

I took a look at the changes gradle made to support Java17, and it looks like it primarily comes down to updating Opcodes.ASM7 to Opcodes.ASM9 in some or all of these locations: https://github.com/search?q=repo%3Aeed3si9n%2Fjarjar-abrams+Opcodes.ASM7&type=code

@MichaelBaker
Copy link

I confirmed locally that updating ASM and changing Opcodes.ASM7 to Opcodes.ASM9 in jarjar-abrams fixed my particular issue.

@eed3si9n eed3si9n closed this as completed Oct 7, 2023
@acruise
Copy link

acruise commented Oct 25, 2023

IIUC, I'm not sure this is fixed when viewed from the context of sbt-assembly... It's not enough for the version of jarjar to be bumped; whoever is creating ClassVisitors needs to pass Opcodes.ASM9 to the constructor.

Can I substitute a patched version of jarjar-abrams in my build? :)

@eed3si9n
Copy link
Member

Here's GitHub Actions https://github.com/sbt/sbt-assembly/actions/runs/6649535607 demonstrating scripted tests on JDK 21.

@cdegroc
Copy link

cdegroc commented Nov 15, 2023

Here's GitHub Actions https://github.com/sbt/sbt-assembly/actions/runs/6649535607 demonstrating scripted tests on JDK 21.

👋 Do you mean this proves sbt-assembly should work with Java 17+ bytecode?

Even with the latest version of sbt-assembly, I've hit this ASM9 issue due to a library using records (Java 14) and sealed classes (Java 17).

Applying the changes suggested above to jarjar-abrams and recompiling sbt-assembly locally with it solved the issue.

I've opened a PR to gather feedback.

@xuwei-k
Copy link
Member

xuwei-k commented Nov 19, 2023

@MichaelBaker
Copy link

I've confirmed that version 2.1.5 fixes my problem. Thanks!

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

No branches or pull requests

7 participants