JuliaInterop / JuliaInterop/JavaCall.jl

Error on JavaCall.init() with Julia >= 1.12

Open
#170 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
125
Forks
53
PR merge metrics
No merged PRs in 30d

Description

julia> using JavaCall

julia> JavaCall.init()
ERROR: TaskFailedException

    nested task error: BoundsError: attempt to access 1-element Vector{Ptr{JavaCall.JNI.JNIEnv}} at index [2]
    Stacktrace:
     [1] throw_boundserror(A::Vector{Ptr{JavaCall.JNI.JNIEnv}}, I::Tuple{Int64})
       @ Base ./essentials.jl:15
     [2] getindex
       @ ./essentials.jl:917 [inlined]
     [3] getindex
       @ ./refpointer.jl:193 [inlined]
     [4] attach_current_thread
       @ ~/.julia/packages/JavaCall/IAoV2/src/JNI.jl:171 [inlined]
     [5] macro expansion
       @ ~/.julia/packages/JavaCall/IAoV2/src/JNI.jl:176 [inlined]
     [6] (::JavaCall.JNI.var"#attach_threads##0#attach_threads##1"{…})(tid::Int64; onethread::Bool)
       @ JavaCall.JNI ./threadingconstructs.jl:276
     [7] #attach_threads##0
       @ ./threadingconstructs.jl:243 [inlined]
     [8] (::Base.Threads.var"#threading_run##0#threading_run##1"{…})()
       @ Base.Threads ./threadingconstructs.jl:177
Stacktrace:
 [1] threading_run(fun::JavaCall.JNI.var"#attach_threads##0#attach_threads##1"{…}, static::Bool)
   @ Base.Threads ./threadingconstructs.jl:196
 [2] macro expansion
   @ ./threadingconstructs.jl:213 [inlined]
 [3] attach_threads
   @ ~/.julia/packages/JavaCall/IAoV2/src/JNI.jl:175 [inlined]
 [4] init_new_vm(libpath::Tuple{String}, opts::OrderedCollections.OrderedSet{String})
   @ JavaCall.JNI ~/.julia/packages/JavaCall/IAoV2/src/JNI.jl:164
 [5] _init(opts::OrderedCollections.OrderedSet{String})
   @ JavaCall ~/.julia/packages/JavaCall/IAoV2/src/jvm.jl:291
 [6] init()
   @ JavaCall ~/.julia/packages/JavaCall/IAoV2/src/jvm.jl:277
 [7] top-level scope
   @ REPL[2]:1
Some type information was truncated. Use `show(err)` to see complete types.

julia> versioninfo()
Julia Version 1.12.0-beta1
Commit c175ace780d (2025-04-02 11:19 UTC)
Build Info:
  Official https://julialang.org release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 16 × AMD Ryzen 7 8840HS w/ Radeon 780M Graphics
  WORD_SIZE: 64
  LLVM: libLLVM-18.1.7 (ORCJIT, znver3)
  GC: Built with stock GC
Threads: 1 default, 1 interactive, 1 GC (on 16 virtual cores)
Environment:
  JULIA_REVISE_POLL = 1
  JULIA_COPY_STACKS = 1

This is probably because of https://github.com/JuliaInterop/JavaCall.jl/blob/2f1824fd963f4d89f85a4b528fbe995d7b4ab7f3/src/JNI.jl#L168-L178

See https://github.com/JuliaFolds2/OhMyThreads.jl/issues/136#issuecomment-2674297965 and https://julialang.org/blog/2023/07/PSA-dont-use-threadid/

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 with src/JNI.jl lines 168-178, where the stack trace shows the failing thread-attachment path, and reproduce JavaCall.init() on Julia 1.12. Review the linked Julia threading guidance and determine why the environment lookup reaches index [2]. Done means JavaCall.init() completes without the BoundsError on the reported setup.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, julia
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.