-
Notifications
You must be signed in to change notification settings - Fork 0
🔧 chore: update version to 3.27.5 and improve service loader fallback… #387
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,19 +13,22 @@ import java.util.* | |
| * @return the service instance of type [T] | ||
| * @throws ServiceConfigurationError if the service of type [T] is not available | ||
| */ | ||
| inline fun <reified T : Any> requiredService(): T = ServiceUtil.serviceWithFallback<T>( | ||
| ServiceLoader.load( | ||
| T::class.java, | ||
| getCallerClass(-1)?.classLoader ?: T::class.java.classLoader | ||
| ), T::class.java | ||
| ) ?: throw ServiceConfigurationError("Service ${T::class.java.name} not available") | ||
| inline fun <reified T : Any> requiredService(): T = ServiceUtil.serviceWithFallback(T::class.java) | ||
| ?: throw ServiceConfigurationError("Service ${T::class.java.name} not available") | ||
|
|
||
| object ServiceUtil { | ||
| @Suppress("UnstableApiUsage") | ||
| private val SERVICE_LOAD_FAILURES_ARE_FATAL = AdventureProperties.SERVICE_LOAD_FAILURES_ARE_FATAL.value() == true | ||
|
|
||
| @Deprecated("Binary compatibility", ReplaceWith("serviceWithFallback(loader, type)"), DeprecationLevel.HIDDEN) | ||
| @PublishedApi | ||
| internal fun <T : Any> serviceWithFallback(loader: ServiceLoader<T>, type: Class<T>): T? { | ||
| return serviceWithFallback(type) | ||
| } | ||
|
|
||
| @PublishedApi | ||
| internal fun <T : Any> serviceWithFallback(type: Class<T>): T? { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This module applies Useful? React with 👍 / 👎. |
||
| val loader = ServiceLoader.load(type, type.classLoader) | ||
| val iterator = loader.iterator() | ||
| var firstFallback: T? = null | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For already-compiled callers of the previous inline
requiredService, the caller class loader is passed in through thisloaderargument. Delegating to the one-arg overload discards that loader and reloads withtype.classLoader, so any existing caller whoseMETA-INF/servicesentry is only visible from its own/plugin class loader will start throwingServiceConfigurationErrorafter upgrading. Please iterate the supplied loader here to preserve the old binary-compatible behavior.Useful? React with 👍 / 👎.