diff --git a/compiler/util-klib/src/org/jetbrains/kotlin/library/impl/KotlinLibraryImpl.kt b/compiler/util-klib/src/org/jetbrains/kotlin/library/impl/KotlinLibraryImpl.kt index e9f98ea89dd..c7aec4f5b2f 100644 --- a/compiler/util-klib/src/org/jetbrains/kotlin/library/impl/KotlinLibraryImpl.kt +++ b/compiler/util-klib/src/org/jetbrains/kotlin/library/impl/KotlinLibraryImpl.kt @@ -21,6 +21,8 @@ import org.jetbrains.kotlin.konan.file.ZipFileSystemAccessor import org.jetbrains.kotlin.konan.properties.Properties import org.jetbrains.kotlin.konan.properties.loadProperties import org.jetbrains.kotlin.library.* +import org.jetbrains.kotlin.util.DummyLogger +import org.jetbrains.kotlin.util.Logger class BaseKotlinLibraryImpl( val access: BaseLibraryAccess, @@ -356,8 +358,25 @@ fun createKotlinLibraryComponents( } fun isKotlinLibrary(libraryFile: File): Boolean = try { - resolveSingleFileKlib(libraryFile) - true + val libraryPath = libraryFile.absolutePath + + /** + * Important: Try to resolve it as a "lenient" library. This will allow to probe a library + * without logging any errors to [DummyLogger] and without any side effects such as throwing an + * exception from [SingleKlibComponentResolver.resolve] if the library is not found. + */ + SingleKlibComponentResolver( + klibFile = libraryPath, + logger = object : Logger { + override fun log(message: String) = Unit // don't log + override fun error(message: String) = Unit // don't log + override fun warning(message: String) = Unit // don't log + override fun fatal(message: String): Nothing = kotlin.error("This function should not be called") + }, + knownIrProviders = emptyList() + ).resolve( + LenientUnresolvedLibrary(libraryPath, libraryVersion = null) + ) != null } catch (e: Throwable) { false }