From a1fce4a30113235c0438084d912c899122bd6c09 Mon Sep 17 00:00:00 2001 From: Claire McGinty Date: Thu, 19 Dec 2024 10:29:35 -0500 Subject: [PATCH] Update default Dataflow add-open opts for Java 17+ --- .../runners/dataflow/DataflowContext.scala | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) 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..4f7f860f1c 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 @@ -41,16 +41,22 @@ 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 - ) { - dataflowPipelineOpts.setJdkAddOpenModules( - List("java.base/java.util=ALL-UNNAMED", "java.base/java.lang.invoke=ALL-UNNAMED").asJava - ) + val javaVersionRe = "^(\\d+)\\..*".r + + sys.props("java.version") match { + case javaVersionRe(version) + if version.toInt >= 17 && dataflowPipelineOpts.getJdkAddOpenModules == null => + dataflowPipelineOpts.setJdkAddOpenModules( + 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 + ) + case _ => // Only add opts for Java 17+ } dataflowOptions.setFilesToStage(new java.util.ArrayList(filesToStage))