Improve diagnostic for missing BuiltInsLoader implementation

Also initialize it lazily to avoid wrapping the exception into
ExceptionInInitializerError

 #KT-20575
This commit is contained in:
Alexander Udalov
2018-01-05 17:48:26 +01:00
parent 50c515deca
commit 42de05f3fa
@@ -34,7 +34,12 @@ interface BuiltInsLoader {
): PackageFragmentProvider
companion object {
val Instance: BuiltInsLoader =
ServiceLoader.load(BuiltInsLoader::class.java, BuiltInsLoader::class.java.classLoader).first()
val Instance: BuiltInsLoader by lazy(LazyThreadSafetyMode.PUBLICATION) {
val implementations = ServiceLoader.load(BuiltInsLoader::class.java, BuiltInsLoader::class.java.classLoader)
implementations.firstOrNull() ?: throw IllegalStateException(
"No BuiltInsLoader implementation was found. Please ensure that the META-INF/services/ is not stripped " +
"from your application and that the Java virtual machine is not running under a security manager"
)
}
}
}