From 2b14afda80f2f3c29c4d697b368728b5ad1aedd4 Mon Sep 17 00:00:00 2001 From: Michel Davit Date: Fri, 20 Dec 2024 10:48:31 +0100 Subject: [PATCH] use same java major extract fn as in build --- .../runners/dataflow/DataflowContext.scala | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 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 4f7f860f1c..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]) @@ -43,20 +46,15 @@ case object DataflowContext extends RunnerContext { // Required for Kryo w/ Java 17+ lazy val dataflowPipelineOpts = options.as(classOf[DataflowPipelineOptions]) - 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+ + if (JavaMajorVersion >= 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 + ) } dataflowOptions.setFilesToStage(new java.util.ArrayList(filesToStage))