Fix NPE from JarURLConnection.getUseCaches when loading compiler plugins
#KT-22513 Fixed
This commit is contained in:
@@ -29,6 +29,8 @@ import org.jetbrains.kotlin.cli.jvm.compiler.CompileEnvironmentException
|
|||||||
import org.jetbrains.kotlin.config.KotlinCompilerVersion
|
import org.jetbrains.kotlin.config.KotlinCompilerVersion
|
||||||
import org.jetbrains.kotlin.config.Services
|
import org.jetbrains.kotlin.config.Services
|
||||||
import java.io.PrintStream
|
import java.io.PrintStream
|
||||||
|
import java.net.URL
|
||||||
|
import java.net.URLConnection
|
||||||
import java.util.function.Predicate
|
import java.util.function.Predicate
|
||||||
|
|
||||||
abstract class CLITool<A : CommonToolArguments> {
|
abstract class CLITool<A : CommonToolArguments> {
|
||||||
@@ -79,6 +81,8 @@ abstract class CLITool<A : CommonToolArguments> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun exec(messageCollector: MessageCollector, services: Services, arguments: A): ExitCode {
|
fun exec(messageCollector: MessageCollector, services: Services, arguments: A): ExitCode {
|
||||||
|
disableURLConnectionCaches()
|
||||||
|
|
||||||
printVersionIfNeeded(messageCollector, arguments)
|
printVersionIfNeeded(messageCollector, arguments)
|
||||||
|
|
||||||
val fixedMessageCollector = if (arguments.suppressWarnings && !arguments.allWarningsAsErrors) {
|
val fixedMessageCollector = if (arguments.suppressWarnings && !arguments.allWarningsAsErrors) {
|
||||||
@@ -92,6 +96,16 @@ abstract class CLITool<A : CommonToolArguments> {
|
|||||||
return execImpl(fixedMessageCollector, services, arguments)
|
return execImpl(fixedMessageCollector, services, arguments)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun disableURLConnectionCaches() {
|
||||||
|
// We disable caches to avoid problems with compiler under daemon, see https://youtrack.jetbrains.com/issue/KT-22513
|
||||||
|
// For some inexplicable reason, URLConnection.setDefaultUseCaches is an instance method modifying a static field,
|
||||||
|
// so we have to create a dummy instance to call that method
|
||||||
|
|
||||||
|
object : URLConnection(URL("file:.")) {
|
||||||
|
override fun connect() = throw UnsupportedOperationException()
|
||||||
|
}.defaultUseCaches = false
|
||||||
|
}
|
||||||
|
|
||||||
// Used in kotlin-maven-plugin (KotlinCompileMojoBase)
|
// Used in kotlin-maven-plugin (KotlinCompileMojoBase)
|
||||||
protected abstract fun execImpl(messageCollector: MessageCollector, services: Services, arguments: A): ExitCode
|
protected abstract fun execImpl(messageCollector: MessageCollector, services: Services, arguments: A): ExitCode
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user