From d4b1cedb2b8fef2d3294c012d3b323a1a4102f61 Mon Sep 17 00:00:00 2001 From: Claire McGinty Date: Fri, 20 Dec 2024 11:10:26 -0500 Subject: [PATCH] Update default Dataflow add-open opts for Java 17+ (#5537) Co-authored-by: Michel Davit --- project/JavaOptions.scala | 3 ++- .../runners/dataflow/DataflowContext.scala | 18 +++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) 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 ) }