libby icon indicating copy to clipboard operation
libby copied to clipboard

[Bug] Relocations doesn't support Java 19+

Open bivashy opened this issue 10 months ago • 0 comments

Description

If library, or transitive dependencies, contains classes compiled with Java 19 or higher, we have such an exception:

Exception in thread "main" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
	at com.alessiodp.libby.relocation.RelocationHelper.relocate(RelocationHelper.java:140)
	at com.alessiodp.libby.LibraryManager.relocate(LibraryManager.java:669)
	at com.alessiodp.libby.LibraryManager.downloadLibrary(LibraryManager.java:564)
	at com.alessiodp.libby.LibraryManager.loadLibrary(LibraryManager.java:719)
	at com.alessiodp.libby.LibraryManager.resolveTransitiveLibraries(LibraryManager.java:703)
	at com.alessiodp.libby.LibraryManager.loadLibrary(LibraryManager.java:721)
	at Example.main(Example.java:35)
Caused by: java.lang.reflect.InvocationTargetException
	at jdk.internal.reflect.GeneratedMethodAccessor10.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at com.alessiodp.libby.relocation.RelocationHelper.relocate(RelocationHelper.java:138)
	... 6 more
Caused by: java.lang.IllegalArgumentException: Unsupported class file major version 63
	at org.objectweb.asm.ClassReader.<init>(ClassReader.java:199)
	at org.objectweb.asm.ClassReader.<init>(ClassReader.java:180)
	at org.objectweb.asm.ClassReader.<init>(ClassReader.java:166)
	at org.objectweb.asm.ClassReader.<init>(ClassReader.java:287)
	at me.lucko.jarrelocator.JarRelocatorTask.processClass(JarRelocatorTask.java:178)
	at me.lucko.jarrelocator.JarRelocatorTask.processEntry(JarRelocatorTask.java:107)
	at me.lucko.jarrelocator.JarRelocatorTask.processEntries(JarRelocatorTask.java:90)
	at me.lucko.jarrelocator.JarRelocator.run(JarRelocator.java:94)
	... 10 more

Which means that Java 19+ classes cannot be relocated.


Reproducing the problem

This can be replicated with jackson-core 2.16.0, or with JDA 2.0.0-beta.20. Code for reproduction:

import java.nio.file.Path;
import java.util.logging.Logger;

import com.alessiodp.libby.Library;
import com.alessiodp.libby.LibraryManager;
import com.alessiodp.libby.StandaloneLibraryManager;
import com.alessiodp.libby.logging.adapters.JDKLogAdapter;

public class Example {
    public static final Library JDA_LIBRARY = Library.builder()
            .groupId("net{}dv8tion")
            .artifactId("JDA")
            .version("5.0.0-beta.20")
            .relocate("net{}dv8tion", "com{}example{}lib{}net{}dv8tion")
            .relocate("com{}iwebpp", "com{}example{}lib{}com{}iwebpp")
            .relocate("org{}apache{}commons", "com{}example{}lib{}org{}apache{}commons")
            .relocate("com{}neovisionaries{}ws", "com{}example{}lib{}com{}neovisionaries{}ws")
            .relocate("com{}fasterxml{}jackson", "com{}example{}lib{}com{}fasterxml{}jackson")
            .relocate("org{}slf4j", "com{}example{}lib{}org{}slf4j")
            .relocate("gnu{}trove", "com{}example{}gnu{}trove")
            .relocate("okhttp3", "com{}example{}lib{}okhttp3")
            .relocate("com{}squareup{}okio", "com{}example{}lib{}com{}squareup{}okio")
            .resolveTransitiveDependencies(true)
            .excludeTransitiveDependency("club{}minnced", "opus-java")
            .build();

    public static void main(String[] args) {
        LibraryManager libraryManager = new StandaloneLibraryManager(
                new JDKLogAdapter(Logger.getLogger(Example.class.getSimpleName())),
                Path.of("."), "libby");
        libraryManager.addMavenCentral();

        libraryManager.loadLibrary(JDA_LIBRARY);
    }
}

Libby 2.0.0-SNAPSHOT was used.

Possible solution

In my opinion we could just use ASM 9.7, because ASM is backward compatible, starting from ASM 4.0. But this may not be a perfect solution, please let me know if there is a are better approach. If you're satisfied with simple ASM version bump I could pull request that.

bivashy avatar Apr 06 '24 16:04 bivashy