armedbear / abcl

Armed Bear Common Lisp <git+https://github.com/armedbear/abcl/> <--> <svn+https://abcl.org/svn> Bridge
https://abcl.org#rdfs:seeAlso<https://gitlab.common-lisp.net/abcl/abcl>
Other
292 stars 30 forks source link

java.lang.reflect.InaccessibleObjectExceptions, possible workaround #684

Open kreuter opened 3 weeks ago

kreuter commented 3 weeks ago

It appears that recentish Java versions enforce stricter access controls for reflection methods than formerly. (Transcript below.)

I don't know if this is the right way to fix it, but it seems that adding --add-opens java.base/java.lang=ALL-UNNAMED to the java startup flags in the abcl script makes this problem go away, at least for the simple cases I've tried.

$ abcl
Failed to introspect virtual threading methods: java.lang.reflect.InaccessibleObjectException: Unable to make public java.lang.Thread java.lang.ThreadBuilders$VirtualThreadFactory.newThread(java.lang.Runnable) accessible: module java.base does not "opens java.lang" to unnamed module @6bd28748
Armed Bear Common Lisp 1.9.2
Java 21.0.5 MacPorts
OpenJDK 64-Bit Server VM
Low-level initialization completed in 0.203 seconds.
Startup completed in 0.899 seconds.
Type ":help" for a list of available commands.
CL-USER(1): (system:process-pid (system:run-program "sleep" '("10") :wait nil))
#<THREAD "interpreter" native {1D8E781E}>: Debugger invoked on condition of type JAVA-EXCEPTION
  Java exception 'java.lang.reflect.InaccessibleObjectException: Unable to make field private final int java.lang.ProcessImpl.pid accessible: module java.base does not "opens java.lang" to unnamed module @6bd28748'.
alanruttenberg commented 3 weeks ago

I do that too but there still remain fields that are inaccessible. I haven't investigated why or whether there is a workaround. I have a feeling that more --add-opens for different modules need to be added to the command line.

easye commented 3 weeks ago

I have half-heartedly been collecting various --add-opens clauses in the ABCL Ant autoconfigure logic (c.f. https://github.com/armedbear/abcl/blob/master/ci/create-abcl-properties.bash#L16).

Aspirationally, I would put all this logic into Common Lisp that would create the necessary wrapper scripts for UNIX/Windows, but that effort has never materialized.