I am using using Java 17 (corretto-17) with Gradle (7.3.3) and Scala (2.12.17), when running unit tests that uses Spark (3.4.1) it fails with:
java.lang.ExceptionInInitializerError: Exception java.lang.IllegalAccessError: class org.apache.spark.storage.StorageUtils$ (in unnamed module @0x5e25a92e) cannot access class sun.nio.ch.DirectBuffer (in module java.base) because module java.base does not export sun.nio.ch to unnamed module @0x5e25a92e [in thread “Test worker”]
The most common answer I’m seeing is to add some VM arguments, like this thread suggests: Running unit tests with Spark 3.3.0 on Java 17 fails with IllegalAccessError: class StorageUtils cannot access class sun.nio.ch.DirectBuffer. That seems to work across the board for others. But there must be another piece to this puzzle because even with those VM arguments, I’m still seeing the same error.
ChewyLime4 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.