diff --git a/compiler/cli/bin/kotlinc b/compiler/cli/bin/kotlinc index 55366b834a4..b1cd40143fd 100755 --- a/compiler/cli/bin/kotlinc +++ b/compiler/cli/bin/kotlinc @@ -67,13 +67,18 @@ fi declare -a kotlin_app +java_version="$(findJavaVersion)" +if [[ $java_version -ge 9 ]]; then + # Workaround the illegal reflective access warning from ReflectionUtil to ResourceBundle.setParent, see IDEA-248785. + java_args=("${java_args[@]}" "--add-opens" "java.base/java.util=ALL-UNNAMED") +fi + if [ -n "$KOTLIN_RUNNER" ]; then java_args=("${java_args[@]}" "-Dkotlin.home=${KOTLIN_HOME}") kotlin_app=("${KOTLIN_HOME}/lib/kotlin-runner.jar" "org.jetbrains.kotlin.runner.Main") else [ -n "$KOTLIN_COMPILER" ] || KOTLIN_COMPILER=org.jetbrains.kotlin.cli.jvm.K2JVMCompiler - java_version="$(findJavaVersion)" if [[ $java_version < 13 ]]; then java_args=("${java_args[@]}" "-noverify") fi diff --git a/compiler/cli/bin/kotlinc.bat b/compiler/cli/bin/kotlinc.bat index a0e67b3ed8e..ec084c06a8f 100644 --- a/compiler/cli/bin/kotlinc.bat +++ b/compiler/cli/bin/kotlinc.bat @@ -40,14 +40,20 @@ shift goto loop :loopend -if "%_KOTLIN_RUNNER%"=="1" ( - java %JAVA_OPTS% "-Dkotlin.home=%_KOTLIN_HOME%" -cp "%_KOTLIN_HOME%\lib\kotlin-runner.jar" ^ +setlocal EnableDelayedExpansion + +call :set_java_version +if !_java_major_version! geq 9 ( + rem Workaround the illegal reflective access warning from ReflectionUtil to ResourceBundle.setParent, see IDEA-248785. + set JAVA_OPTS=!JAVA_OPTS! "--add-opens" "java.base/java.util=ALL-UNNAMED" +) + +if "!_KOTLIN_RUNNER!"=="1" ( + java !JAVA_OPTS! "-Dkotlin.home=%_KOTLIN_HOME%" -cp "%_KOTLIN_HOME%\lib\kotlin-runner.jar" ^ org.jetbrains.kotlin.runner.Main %KOTLIN_OPTS% ) else ( - setlocal EnableDelayedExpansion set _ADDITIONAL_CLASSPATH= - call :set_java_version if !_java_major_version! lss 13 ( set JAVA_OPTS=!JAVA_OPTS! "-noverify" ) diff --git a/compiler/tests/org/jetbrains/kotlin/cli/LauncherScriptTest.kt b/compiler/tests/org/jetbrains/kotlin/cli/LauncherScriptTest.kt index 1521c342c19..32b24b54b04 100644 --- a/compiler/tests/org/jetbrains/kotlin/cli/LauncherScriptTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/cli/LauncherScriptTest.kt @@ -33,7 +33,8 @@ class LauncherScriptTest : TestCaseWithTmpdir() { expectedStdout: String = "", expectedStderr: String = "", expectedExitCode: Int = 0, - workDirectory: File? = null + workDirectory: File? = null, + environment: Map = emptyMap(), ) { val executableFileName = if (SystemInfo.isWindows) "$executableName.bat" else executableName val launcherFile = File(PathUtil.kotlinPathsForDistDirectory.homePath, "bin/$executableFileName") @@ -43,9 +44,10 @@ class LauncherScriptTest : TestCaseWithTmpdir() { // So, use ProcessBuilder instead. val pb = ProcessBuilder( launcherFile.absolutePath, - // In cmd, `=` is delimeter, so we need to surround parameter with quotes. + // In cmd, `=` is delimiter, so we need to surround parameter with quotes. *quoteIfNeeded(args) ) + pb.environment().putAll(environment) pb.directory(workDirectory) val process = pb.start() val stdout = @@ -334,4 +336,17 @@ fun f() : Result = Result.success(42) ) runProcess("kotlin", "-howtorun", "classfile", "test.HelloWorldKt", expectedStdout = "Hello!\n", workDirectory = tmpdir) } + + fun testKotlincJdk15() { + val jdk15 = mapOf("JAVA_HOME" to KtTestUtil.getJdk15Home().absolutePath) + runProcess( + "kotlinc", "$testDataDirectory/helloWorld.kt", "-d", tmpdir.path, + environment = jdk15, + ) + + runProcess( + "kotlin", "-e", "listOf('O'.toString() + 'K')", + expectedStdout = "[OK]\n", environment = jdk15, + ) + } }