Add JDK roots to the beginning of the roots list
This behavior was used until 6a1b6d10d8, where the JDK has
unintentionally started to be added to the end of the list, breaking
code which depended on libraries which bundle something from the JDK
#KT-21299 Fixed
This commit is contained in:
@@ -588,11 +588,13 @@ class KotlinCoreEnvironment private constructor(
|
||||
}
|
||||
|
||||
if (!CoreJrtFileSystem.isModularJdk(javaRoot)) {
|
||||
addJvmClasspathRoots(classesRoots)
|
||||
if (classesRoots.isEmpty()) {
|
||||
val messageCollector = get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
|
||||
messageCollector?.report(ERROR, "No class roots are found in the JDK path: $javaRoot")
|
||||
}
|
||||
else {
|
||||
addJvmSdkRoots(classesRoots)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,10 @@ fun CompilerConfiguration.addJvmClasspathRoots(files: List<File>) {
|
||||
files.forEach(this::addJvmClasspathRoot)
|
||||
}
|
||||
|
||||
fun CompilerConfiguration.addJvmSdkRoots(files: List<File>) {
|
||||
addAll(JVMConfigurationKeys.CONTENT_ROOTS, 0, files.map(::JvmClasspathRoot))
|
||||
}
|
||||
|
||||
val CompilerConfiguration.jvmClasspathRoots: List<File>
|
||||
get() = getList(JVMConfigurationKeys.CONTENT_ROOTS).filterIsInstance<JvmClasspathRoot>().map(JvmContentRoot::file)
|
||||
|
||||
|
||||
@@ -90,12 +90,16 @@ public class CompilerConfiguration {
|
||||
}
|
||||
|
||||
public <T> void addAll(@NotNull CompilerConfigurationKey<List<T>> key, @NotNull Collection<T> values) {
|
||||
addAll(key, getList(key).size(), values);
|
||||
}
|
||||
|
||||
public <T> void addAll(@NotNull CompilerConfigurationKey<List<T>> key, int index, @NotNull Collection<T> values) {
|
||||
checkReadOnly();
|
||||
checkForNullElements(values);
|
||||
Key<List<T>> ideaKey = key.ideaKey;
|
||||
map.computeIfAbsent(ideaKey, k -> new ArrayList<T>());
|
||||
List<T> list = (List<T>) map.get(ideaKey);
|
||||
list.addAll(values);
|
||||
list.addAll(index, values);
|
||||
}
|
||||
|
||||
public CompilerConfiguration copy() {
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package java.util;
|
||||
|
||||
public class Date {
|
||||
public static void methodWhichDoesNotExistInJdk() {}
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
compiler/testData/compileKotlinAgainstCustomBinaries/classFromJdkInLibrary/source.kt:4:10: error: unresolved reference: methodWhichDoesNotExistInJdk
|
||||
Date.methodWhichDoesNotExistInJdk()
|
||||
^
|
||||
COMPILATION_ERROR
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
import java.util.Date
|
||||
|
||||
fun foo() {
|
||||
Date.methodWhichDoesNotExistInJdk()
|
||||
}
|
||||
+5
@@ -434,6 +434,11 @@ class CompileKotlinAgainstCustomBinariesTest : AbstractKotlinCompilerIntegration
|
||||
assertEquals(result[0], result[1])
|
||||
}
|
||||
|
||||
fun testClassFromJdkInLibrary() {
|
||||
val library = compileLibrary("library")
|
||||
compileKotlin("source.kt", tmpdir, listOf(library))
|
||||
}
|
||||
|
||||
companion object {
|
||||
// compiler before 1.1.4 version did not include suspension marks into bytecode.
|
||||
private fun stripSuspensionMarksToImitateLegacyCompiler(bytes: ByteArray): Pair<ByteArray, Int> {
|
||||
|
||||
+2
-1
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.cli.common.messages.MessageRenderer
|
||||
import org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector
|
||||
import org.jetbrains.kotlin.cli.common.repl.*
|
||||
import org.jetbrains.kotlin.cli.jvm.config.addJvmClasspathRoots
|
||||
import org.jetbrains.kotlin.cli.jvm.config.addJvmSdkRoots
|
||||
import org.jetbrains.kotlin.cli.jvm.repl.GenericReplCompiler
|
||||
import org.jetbrains.kotlin.config.*
|
||||
import org.jetbrains.kotlin.script.KotlinScriptDefinition
|
||||
@@ -67,7 +68,7 @@ class KotlinJsr223JvmLocalScriptEngine(
|
||||
}
|
||||
|
||||
private fun makeCompilerConfiguration() = CompilerConfiguration().apply {
|
||||
addJvmClasspathRoots(PathUtil.getJdkClassesRootsFromCurrentJre())
|
||||
addJvmSdkRoots(PathUtil.getJdkClassesRootsFromCurrentJre())
|
||||
addJvmClasspathRoots(templateClasspath)
|
||||
put(CommonConfigurationKeys.MODULE_NAME, "kotlin-script")
|
||||
languageVersionSettings = LanguageVersionSettingsImpl(
|
||||
|
||||
Reference in New Issue
Block a user