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

NoClassCefFoundError on JDABuilder.build after upgrade from alpha.9 to alpha.10 #2129

Closed
3 tasks done
TheHusseler opened this issue May 10, 2022 · 10 comments
Closed
3 tasks done

Comments

@TheHusseler
Copy link

TheHusseler commented May 10, 2022

General Troubleshooting

  • I have checked for similar issues on the Issue-tracker.
  • I have updated to the latest JDA version
  • I have checked the branches or the maintainers' PRs for upcoming bug fixes.

Expected Behaviour

I'm updating a plugin that uses JDA to alpha.11 for Modals. However, I've since narrowed the issue down to alpha.10, as the code works fine in 9 but not 10.

I get the exception below after starting the plugin. It seems to be related to JDABuilder.build, I've provided the code that calls that below as well. Line 163, the one mentioned in the exception is specifically the line with .build(); This is the start of the thread calling it, I haven't included lines after the exception occurs.

Since this is for the discord connection, I've included the code that spins up the thread.

I tried looking through the commits for alpha.10 to see what may have caused this but I'm not sure. Plus, this code wasn't my contribution to the project, I'm not sure what could have changed that would have affected this. If there's any more code you'd like me to post, I can.

Code Example for Reproduction Steps

public static class DiscordConnectThread extends Thread {
        public String code;
        public DiscordConnection conn;
        public Runnable ender;
        public ScriptEntry scriptEntry;
        public HashSet<GatewayIntent> intents = new HashSet<>(Arrays.asList(GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_EMOJIS, GatewayIntent.GUILD_MESSAGE_REACTIONS,
                GatewayIntent.GUILD_MESSAGES, GatewayIntent.DIRECT_MESSAGE_REACTIONS, GatewayIntent.DIRECT_MESSAGES));

        @Override
        public void run() {
            try {
                try {
                    JDA jda;
                    PrintStream currentErr = System.err;
                    System.setErr(altLogger);
                    try {
                        jda = JDABuilder.createDefault(code)
                                .enableCache(Arrays.stream(CacheFlag.values()).filter(f -> f.getRequiredIntent() == null || intents.contains(f.getRequiredIntent())).collect(Collectors.toList()))
                                .enableIntents(intents)
                                .setMemberCachePolicy(MemberCachePolicy.ALL)
                                .setAutoReconnect(true)
                                .setLargeThreshold(100000)
                                .setChunkingFilter(ChunkingFilter.ALL)
                                .build();
               //Line above is 163, where the exception occurs
                    }
                    finally {
                        System.setErr(currentErr);
                    }
                    conn.client = jda;
                    jda.awaitReady();
                }

Code for JDABuilder or DefaultShardManagerBuilder used

DiscordConnection dc = new DiscordConnection();
        dc.botID = id;
       
       //Skipping code
       //Skipped code for getting the "codeRaw" which is just the token in this case

            codeRaw = codeRaw.trim();
            DiscordConnectThread dct = new DiscordConnectThread();
            dct.scriptEntry = scriptEntry;
            dct.code = codeRaw;
            dct.conn = dc;
            dct.ender = () -> scriptEntry.setFinished(true);
            if (intents != null) {
                try {
                    for (String intent : intents) {
                        dct.intents.add(GatewayIntent.valueOf(intent.toUpperCase()));
                    }
                }
                catch (IllegalArgumentException ex) {
                    Debug.echoError("Invalid 'intents' input - " + ex.getMessage());
                    scriptEntry.setFinished(true);
                    DenizenDiscordBot.instance.connections.remove(id);
                    return;
                }
            }
            dct.start();

Exception or Error

[16:39:42] [Thread-30/WARN]: Exception in thread "Thread-30" java.lang.NoClassDefFoundError: kotlin/Unit
[16:39:42] [Thread-30/WARN]: 	at dDiscordBot-0.7-bUnknown.jar//com.denizenscript.shaded.okhttp3.Dispatcher.setMaxRequestsPerHost(Dispatcher.kt:70)
[16:39:42] [Thread-30/WARN]: 	at dDiscordBot-0.7-bUnknown.jar//com.denizenscript.shaded.net.dv8tion.jda.internal.utils.IOUtil.newHttpClientBuilder(IOUtil.java:72)
[16:39:42] [Thread-30/WARN]: 	at dDiscordBot-0.7-bUnknown.jar//com.denizenscript.shaded.net.dv8tion.jda.api.JDABuilder.build(JDABuilder.java:1741)
[16:39:42] [Thread-30/WARN]: 	at dDiscordBot-0.7-bUnknown.jar//com.denizenscript.ddiscordbot.commands.DiscordConnectCommand$DiscordConnectThread.run(DiscordConnectCommand.java:163)
@Andre601
Copy link
Contributor

This is just a guess but could it be a conflicting OkHttp Version?
If the project (From what I can see is it DenizenScript) is using OkHttp, make sure the version is at least the one JDA is using, because the NoClassDefFoundException points out that kotlin/Unit is missing and since JDA itself isn't a pure kotlin project - and okhttp3 is mentioned in the entries - would my guess go towards that.

@TheHusseler
Copy link
Author

TheHusseler commented May 11, 2022

Did OkHttp get updated recently in JDA?
I did a search for OkHttp and found there is some stuff going on with okhttp in the pom. I'll look into what version JDA is using
<include>com.squareup.okhttp3:**</include>

@TheHusseler
Copy link
Author

So I don't believe that's it. The okhttp3 reference in the pom isn't actually setting up a dependency. So there isn't a conflicting version as far as I can tell

@MinnDevelopment
Copy link
Member

The issue indeed seems to be an incompatible version of OkHTTP. You can use mvn dependency:tree -Dverbose to get a debug output of all your dependencies. Try checking for okhttp in that.

@TheHusseler
Copy link
Author

TheHusseler commented May 11, 2022

It doesn't seem to be the case. Just to be clear and careful, here's the dependency tree:

[INFO] +- org.spigotmc:spigot-api:jar:1.18.2-R0.1-SNAPSHOT:provided
[INFO] |  +- commons-lang:commons-lang:jar:2.6:provided
[INFO] |  +- com.google.guava:guava:jar:31.0.1-jre:provided
[INFO] |  |  +- com.google.guava:failureaccess:jar:1.0.1:provided
[INFO] |  |  +- com.google.guava:listenablefuture:jar:9999.0-empty-to-avoid-conflict-with-guava:provided
[INFO] |  |  +- (com.google.code.findbugs:jsr305:jar:3.0.2:provided - omitted for duplicate)
[INFO] |  |  +- org.checkerframework:checker-qual:jar:3.12.0:provided
[INFO] |  |  +- com.google.errorprone:error_prone_annotations:jar:2.7.1:provided
[INFO] |  |  \- com.google.j2objc:j2objc-annotations:jar:1.3:provided
[INFO] |  +- com.google.code.gson:gson:jar:2.8.9:provided
[INFO] |  +- net.md-5:bungeecord-chat:jar:1.16-R0.4:provided
[INFO] |  |  +- (com.google.code.gson:gson:jar:2.8.0:provided - omitted for conflict with 2.8.9)
[INFO] |  |  \- (com.google.guava:guava:jar:21.0:provided - omitted for conflict with 31.0.1-jre)
[INFO] |  \- org.yaml:snakeyaml:jar:1.30:provided
[INFO] +- com.denizenscript:denizen:jar:1.2.4-SNAPSHOT:provided
[INFO] \- net.dv8tion:JDA:jar:5.0.0-alpha.11:compile
[INFO]    +- com.google.code.findbugs:jsr305:jar:3.0.2:compile
[INFO]    +- org.jetbrains:annotations:jar:23.0.0:compile
[INFO]    +- org.slf4j:slf4j-api:jar:1.7.36:compile
[INFO]    +- com.neovisionaries:nv-websocket-client:jar:2.14:compile
[INFO]    +- com.squareup.okhttp3:okhttp:jar:4.9.3:compile
[INFO]    |  +- com.squareup.okio:okio:jar:2.8.0:compile
[INFO]    |  |  +- (org.jetbrains.kotlin:kotlin-stdlib:jar:1.4.0:compile - omitted for conflict with 1.4.10)
[INFO]    |  |  \- org.jetbrains.kotlin:kotlin-stdlib-common:jar:1.4.0:compile
[INFO]    |  \- org.jetbrains.kotlin:kotlin-stdlib:jar:1.4.10:compile
[INFO]    |     +- (org.jetbrains.kotlin:kotlin-stdlib-common:jar:1.4.10:compile - omitted for conflict with 1.4.0)
[INFO]    |     \- (org.jetbrains:annotations:jar:13.0:compile - omitted for conflict with 23.0.0)
[INFO]    +- club.minnced:opus-java:jar:1.1.1:compile
[INFO]    |  +- club.minnced:opus-java-api:jar:1.1.1:compile
[INFO]    |  |  \- net.java.dev.jna:jna:jar:4.4.0:runtime
[INFO]    |  \- club.minnced:opus-java-natives:jar:1.1.1:compile
[INFO]    +- org.apache.commons:commons-collections4:jar:4.4:compile
[INFO]    +- net.sf.trove4j:trove4j:jar:3.0.3:runtime
[INFO]    +- com.fasterxml.jackson.core:jackson-core:jar:2.13.2:runtime
[INFO]    \- com.fasterxml.jackson.core:jackson-databind:jar:2.13.2.2:runtime
[INFO]       +- com.fasterxml.jackson.core:jackson-annotations:jar:2.13.2:runtime
[INFO]       \- (com.fasterxml.jackson.core:jackson-core:jar:2.13.2:runtime - omitted for duplicate)

That said, there are conflicts with the Kotlin dependencies of okhttp3.

@MinnDevelopment
Copy link
Member

What is your pom.xml? Are you minimizing your jar? Is the deployment environment preventing class loading?

@TheHusseler
Copy link
Author

https://github.com/DenizenScript/dDiscordBot/blob/master/pom.xml
Here's the most recent pom for the project, only difference between this one and my working one is updating JDA's version to alpha.10

@Andre601
Copy link
Contributor

https://github.com/DenizenScript/dDiscordBot/blob/master/pom.xml Here's the most recent pom for the project, only difference between this one and my working one is updating JDA's version to alpha.10

This answers some of minn's questions, mainly if you minimize your jar (https://github.com/DenizenScript/dDiscordBot/blob/master/pom.xml#L99)

@TheHusseler
Copy link
Author

Yeah and I'm looking into whether the deployment environment is preventing class loading now. If it's something that would have been a problem in earlier versions of JDA then I imagine it's a no since those worked, but I'll get confirmation

@TheHusseler
Copy link
Author

I figured it out, i hadn't accounted for the new dependencies that were added in this release.

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

No branches or pull requests

3 participants