@@ -13,14 +13,18 @@ internal class MainCommandLineProcessor : CommandLineProcessor {
1313
1414 override val pluginOptions: Collection <AbstractCliOption >
1515 get() = threadLocalParameters.get()?.pluginOptions
16- ? : error(" MainCommandLineProcessor::pluginOptions accessed before thread local parameters have been set" )
16+ ? : emptyList<AbstractCliOption >().also {
17+ // Handle unset parameters gracefully because this plugin may be accidentally called by other tools that
18+ // discover it on the classpath (for example the kotlin jupyter kernel).
19+ System .err.println (" WARNING: MainCommandLineProcessor::pluginOptions accessed before thread local parameters have been set" )
20+ }
1721
1822 companion object {
1923 const val pluginId = " com.tschuchort.compiletesting.maincommandlineprocessor"
2024
2125 /* * This CommandLineProcessor is instantiated by K2JVMCompiler using
2226 * a service locator. So we can't just pass parameters to it easily.
23- * Instead we need to use a thread-local global variable to pass
27+ * Instead, we need to use a thread-local global variable to pass
2428 * any parameters that change between compilations
2529 */
2630 val threadLocalParameters: ThreadLocal <ThreadLocalParameters > = ThreadLocal ()
@@ -67,6 +71,13 @@ internal class MainCommandLineProcessor : CommandLineProcessor {
6771 }
6872
6973 override fun processOption (option : AbstractCliOption , value : String , configuration : CompilerConfiguration ) {
74+ // Handle unset parameters gracefully because this plugin may be accidentally called by other tools that
75+ // discover it on the classpath (for example the kotlin jupyter kernel).
76+ if (threadLocalParameters.get() == null ) {
77+ System .err.println (" WARNING: MainCommandLineProcessor::processOption accessed before thread local parameters have been set" )
78+ return
79+ }
80+
7081 val (foreignPluginId, foreignOptionName) = decodeForeignOptionName(option.optionName)
7182 val params = threadLocalParameters.get()
7283
0 commit comments