title: Apache Spark 3.3.0 breaks on Java 17 with "cannot access class sun.nio.ch.DirectBuffer"
body: <p>A similar question was asked at <a href="https://stackoverflow.com/q/72724816">Running unit tests with Spark 3.3.0 on Java 17 fails with IllegalAccessError: class StorageUtils cannot access class sun.nio.ch.DirectBuffer</a>, but that question (and solution) was only about unit tests. For me Spark is breaking actually running the program.</p>
  <p>According to the <a href="https://spark.apache.org/docs/latest/" rel="noreferrer">Spark overview</a>, Spark works with Java 17. I'm using Temurin-17.0.4+8 (build 17.0.4+8) on Windows 10, including Spark 3.3.0 in Maven like this:</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;scala.version&gt;2.13&lt;/scala.version&gt;
  &lt;spark.version&gt;3.3.0&lt;/spark.version&gt;
  ...
  &lt;dependency&gt;
    &lt;groupId&gt;org.apache.spark&lt;/groupId&gt;
    &lt;artifactId&gt;spark-core_${scala.version}&lt;/artifactId&gt;
    &lt;version&gt;${spark.version}&lt;/version&gt;
  &lt;/dependency&gt;
  
  &lt;dependency&gt;
    &lt;groupId&gt;org.apache.spark&lt;/groupId&gt;
    &lt;artifactId&gt;spark-sql_${scala.version}&lt;/artifactId&gt;
    &lt;version&gt;${spark.version}&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  <p>I try to run a simple program:</p>
  <pre class="lang-java prettyprint-override"><code>final SparkSession spark = SparkSession.builder().appName(&quot;Foo Bar&quot;).master(&quot;local&quot;).getOrCreate();
  final Dataset&lt;Row&gt; df = spark.read().format(&quot;csv&quot;).option(&quot;header&quot;, &quot;false&quot;).load(&quot;/path/to/file.csv&quot;);
  df.show(5);
  </code></pre>
  <p>That breaks all over the place:</p>
  <pre><code>Caused by: java.lang.IllegalAccessError: class org.apache.spark.storage.StorageUtils$ (in unnamed module @0x59d016c9) cannot access class sun.nio.ch.DirectBuffer (in module java.base) because module java.base does not export sun.nio.ch to unnamed module @0x59d016c9
      at org.apache.spark.storage.StorageUtils$.&lt;clinit&gt;(StorageUtils.scala:213)
      at org.apache.spark.storage.BlockManagerMasterEndpoint.&lt;init&gt;(BlockManagerMasterEndpoint.scala:114)
      at org.apache.spark.SparkEnv$.$anonfun$create$9(SparkEnv.scala:353)
      at org.apache.spark.SparkEnv$.registerOrLookupEndpoint$1(SparkEnv.scala:290)
      at org.apache.spark.SparkEnv$.create(SparkEnv.scala:339)
      at org.apache.spark.SparkEnv$.createDriverEnv(SparkEnv.scala:194)
      at org.apache.spark.SparkContext.createSparkEnv(SparkContext.scala:279)
      at org.apache.spark.SparkContext.&lt;init&gt;(SparkContext.scala:464)
      at org.apache.spark.SparkContext$.getOrCreate(SparkContext.scala:2704)
      at org.apache.spark.sql.SparkSession$Builder.$anonfun$getOrCreate$2(SparkSession.scala:953)
      at scala.Option.getOrElse(Option.scala:201)
      at org.apache.spark.sql.SparkSession$Builder.getOrCreate(SparkSession.scala:947)
  </code></pre>
  <p>Spark is obviously doing things one is not supposed to do in Java 17.</p>
  <p>Disappointing. How do I get around this?</p>