Reflection on internal classes fails under Java 9


  • Patch:
    Code and Test
  • Approval:


Due to changes in reflective access for the Jigsaw module system in Java 9, the Reflector will now fail on some cases that worked in previous Java versions.

(def fac (
(.createXMLStreamReader fac ( ""))

Here fac will be an instance of, which is an implementation of In the new java.xml module, is an exported package, but the XMLInputFactoryImpl is an internal implementation of the public interface in that package. The invocation of createXMLStreamReader will be reflective and the Reflector will attempt to invoke the method based on the implementation class, which is not accessible outside the module, yielding:

IllegalAccessException class clojure.lang.Reflector cannot access class (in module java.xml) because module java.xml does not export to unnamed module @4722ef0c
	jdk.internal.reflect.Reflection.throwIllegalAccessException (
	jdk.internal.reflect.Reflection.throwIllegalAccessException (
	jdk.internal.reflect.Reflection.ensureMemberAccess (
	java.lang.reflect.AccessibleObject.slowCheckMemberAccess (
	java.lang.reflect.AccessibleObject.checkAccess (
	java.lang.reflect.Method.invoke (
	clojure.lang.Reflector.invokeMatchingMethod (
	clojure.lang.Reflector.invokeInstanceMethod (

One workaround here is to avoid the reflective call by type-hinting to the public exported interface:

(.createXMLStreamReader ^ fac ( ""))

Another (undesirable) workaround is to export the private package from java.xml to the unnamed module (which is the module used when code is loaded from the classpath rather than from a module) when invoking java/javac:

java --add-exports=java.xml/ --add-exports=java.xml/ --add-exports=java.xml/ ...

Proposed: The attached patch will check for and catch IllegalAccessException in the Reflector. When it occurs, the Reflector will attempt to invoke the method on all super-classes and super-interfaces in case one of them can succeed.

Patch: tcrawley.CLJ-2066.2017-09-07.patch

More info:



Vote (3)
Watch (9)


  • Created: