Skip to content

Commit

Permalink
Update default Dataflow add-open opts for Java 17+ (#5537)
Browse files Browse the repository at this point in the history
Co-authored-by: Michel Davit <micheld@spotify.com>
  • Loading branch information
clairemcginty and RustedBones authored Dec 20, 2024
1 parent 1c931f7 commit d4b1ced
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
3 changes: 2 additions & 1 deletion project/JavaOptions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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
)
}

Expand Down

0 comments on commit d4b1ced

Please sign in to comment.