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

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

Open
kreuter opened this issue Nov 6, 2024 · 2 comments
Open

Comments

@kreuter
Copy link

kreuter commented Nov 6, 2024

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
Copy link
Collaborator

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
Copy link
Collaborator

easye commented Nov 6, 2024

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.

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