Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled
javaVersion=25
mcVersion=26.2
group=dev.slne.surf.api
version=3.27.4
version=3.27.5
relocationPrefix=dev.slne.surf.api.libs
snapshot=false
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve the caller-provided service loader

For already-compiled callers of the previous inline requiredService, the caller class loader is passed in through this loader argument. Delegating to the one-arg overload discards that loader and reloads with type.classLoader, so any existing caller whose META-INF/services entry is only visible from its own/plugin class loader will start throwing ServiceConfigurationError after upgrading. Please iterate the supplied loader here to preserve the old binary-compatible behavior.

Useful? React with 👍 / 👎.

}

@PublishedApi
internal fun <T : Any> serviceWithFallback(type: Class<T>): T? {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Update the API dump for the new ABI

This module applies api-validation, and the tracked surf-api-core/surf-api-core/api/surf-api-core.api still only lists the existing two-arg serviceWithFallback entry. Because @PublishedApi internal members are emitted in the public ABI, adding this overload without updating the API dump will make :surf-api-core:surf-api-core:apiCheck fail for builds/releases with the expected JDK. Please update the dump with the new signature or avoid adding a new ABI entry.

Useful? React with 👍 / 👎.

val loader = ServiceLoader.load(type, type.classLoader)
val iterator = loader.iterator()
var firstFallback: T? = null

Expand Down
Loading