From 77aa313b644c0e20cda70a383d79f7b96cc1240c Mon Sep 17 00:00:00 2001 From: Graham Date: Sun, 12 Apr 2020 20:23:16 +0100 Subject: [PATCH] Only use StackFrameClassWriter where required Java 11's Pack200 implementation complains if stack map frames are present, and passes the classes through unmodified. I'm not sure why. Stack map frames are only required in Java 7, so for 6 and below a reasonable workaround is to not emit them. A nice side effect of this change is that the jar files created by the bundler are be smaller. The pack200 files are too, and would be even if the classes were not passed through unmodified. --- asm/src/main/java/dev/openrs2/asm/classpath/Library.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/asm/src/main/java/dev/openrs2/asm/classpath/Library.kt b/asm/src/main/java/dev/openrs2/asm/classpath/Library.kt index 7b2d59443e..2b35b227d7 100644 --- a/asm/src/main/java/dev/openrs2/asm/classpath/Library.kt +++ b/asm/src/main/java/dev/openrs2/asm/classpath/Library.kt @@ -1,12 +1,15 @@ package dev.openrs2.asm.classpath import com.github.michaelbull.logging.InlineLogger +import dev.openrs2.asm.ClassVersionUtils import dev.openrs2.asm.NopClassVisitor import dev.openrs2.asm.remap import dev.openrs2.compress.gzip.Gzip import dev.openrs2.crypto.Pkcs12KeyStore import dev.openrs2.util.io.DeterministicJarOutputStream import org.objectweb.asm.ClassReader +import org.objectweb.asm.ClassWriter +import org.objectweb.asm.Opcodes import org.objectweb.asm.commons.Remapper import org.objectweb.asm.tree.ClassNode import org.objectweb.asm.util.CheckClassAdapter @@ -70,7 +73,11 @@ class Library constructor() : Iterable { fun writeJar(classPath: ClassPath, out: OutputStream, manifest: Manifest? = null) { DeterministicJarOutputStream.create(out, manifest).use { jar -> for (clazz in classes.values) { - val writer = StackFrameClassWriter(classPath) + val writer = if (ClassVersionUtils.gte(clazz.version, Opcodes.V1_7)) { + StackFrameClassWriter(classPath) + } else { + ClassWriter(ClassWriter.COMPUTE_MAXS) + } clazz.accept(writer)