AlessioDP / libby

A runtime dependency management library for plugins running in Java-based Minecraft server platforms.
MIT License
81 stars 20 forks source link

[Bug] Relocations doesn't support Java 19+ #46

Closed bivashy closed 3 months ago

bivashy commented 6 months ago

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.

TauCubed commented 3 months ago

Having the same issue.

Edit: Applied bivashy's solution and published a package to https://gitlab.com/TauCu/libby/-/packages for those interested. Built on 1.3.0

frengor commented 3 months ago

Sorry for the delay, fixed in 1.3.1

frafol commented 2 weeks ago

Having the same issue with latest JDA release which is compiled in Java 21.

frengor commented 1 week ago

@frafol Are you using the latest Libby version? Libby is using asm and asm-common 9.7, which support up to Java 23.