PaperMC / PaperMC/tack

No thread context classloader when invoking server main, breaks ServiceLoader lookups (javax.script on Purpur)

Open Beginner friendly
#2 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
24
Forks
3
PR merge metrics
No merged PRs in 30d

Description

Booting Purpur 1.21.7 with tack 0.1.1-beta (source build) dies while
loading the world. Purpur gets null back from its javax.script
lookup (Rhino), so Entity.scriptEngine is null. Same jar works
fine under plain java and under Paperclip.

Env: Debian hosts, server runs in Docker on
amazoncorretto:26-al2023 (glibc, tack needs it).

tack invokes main on a JNI-attached thread without setting a
context classloader first, so ServiceLoader falls back to
bootstrap and never sees the app classpath. Setting it before
the call, the way Paperclip does, fixes it. The snippet below
is what we run in exec_jvm (src/launcher.rs), right before
the main_class lookup, on 11 prod servers since late August:

let system_loader = env
    .call_static_method(
        jni_str!("java/lang/ClassLoader"),
        jni_str!("getSystemClassLoader"),
        jni_sig!("()Ljava/lang/ClassLoader;"),
        &[],
    )?
    .l()
    .into_error()?;
let current_thread = env
    .call_static_method(
        jni_str!("java/lang/Thread"),
        jni_str!("currentThread"),
        jni_sig!("()Ljava/lang/Thread;"),
        &[],
    )?
    .l()
    .into_error()?;
env.call_method(
    &current_thread,
    jni_str!("setContextClassLoader"),
    jni_sig!("(Ljava/lang/ClassLoader;)V"),
    &[JValue::Object(&system_loader)],
)?;

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/launcher.rs at the exec_jvm entry point and inspect the JNI thread setup immediately before the main_class lookup. Reproduce the reported Purpur/Rhino ServiceLoader failure if possible; done means Purpur receives a working javax.script engine when launched through tack.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, rust
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
88/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.