diff --git a/project/JavaOptions.scala b/project/JavaOptions.scala index 3a4798c086..4b41456101 100644 --- a/project/JavaOptions.scala +++ b/project/JavaOptions.scala @@ -66,7 +66,8 @@ object JavaOptions { property("file.encoding", "UTF-8"), addOpens("java.base", "java.util", "ALL-UNNAMED"), addOpens("java.base", "java.lang.invoke", "ALL-UNNAMED"), - addOpens("java.base", "java.lang", "ALL-UNNAMED") + addOpens("java.base", "java.lang", "ALL-UNNAMED"), + addOpens("java.base", "java.nio", "ALL-UNNAMED") ) ) diff --git a/scio-core/src/main/scala/com/spotify/scio/runners/dataflow/DataflowContext.scala b/scio-core/src/main/scala/com/spotify/scio/runners/dataflow/DataflowContext.scala index a3bfddf263..d43bfa63d0 100644 --- a/scio-core/src/main/scala/com/spotify/scio/runners/dataflow/DataflowContext.scala +++ b/scio-core/src/main/scala/com/spotify/scio/runners/dataflow/DataflowContext.scala @@ -30,6 +30,9 @@ import scala.jdk.CollectionConverters._ /** Dataflow runner specific context. */ case object DataflowContext extends RunnerContext { + private lazy val JavaMajorVersion: Int = + System.getProperty("java.version").stripPrefix("1.").takeWhile(_.isDigit).toInt + override def prepareOptions(options: PipelineOptions, artifacts: List[String]): Unit = { val classLoader = classOf[DataflowRunner].getClassLoader val dataflowOptions = options.as(classOf[DataflowPipelineWorkerPoolOptions]) @@ -41,15 +44,16 @@ case object DataflowContext extends RunnerContext { .filesToStage(options, classLoader, localArtifacts, artifacts) .asJavaCollection - // Required for Kryo w/ Java 17 + // Required for Kryo w/ Java 17+ lazy val dataflowPipelineOpts = options.as(classOf[DataflowPipelineOptions]) - if ( - sys - .props("java.version") - .startsWith("17.") && dataflowPipelineOpts.getJdkAddOpenModules == null - ) { + if (JavaMajorVersion >= 17 && dataflowPipelineOpts.getJdkAddOpenModules == null) { dataflowPipelineOpts.setJdkAddOpenModules( - List("java.base/java.util=ALL-UNNAMED", "java.base/java.lang.invoke=ALL-UNNAMED").asJava + List( + "java.base/java.util=ALL-UNNAMED", + "java.base/java.lang.invoke=ALL-UNNAMED", + "java.base/java.lang=ALL-UNNAMED", + "java.base/java.nio=ALL-UNNAMED" + ).asJava ) }