From b6fd6c1bca24219d257e9df39c4a67c4f074a04b Mon Sep 17 00:00:00 2001 From: Nikita Katkov Date: Tue, 10 Mar 2026 21:18:22 +0100 Subject: [PATCH] IJPL-238173 [rpc] Introduce more restrictions to avoid marking too many kotlin&rpc internals as a part of api surface The suggested state is sufficient for accessing classes and checking instances, but it prevents from creating new instances of platform primitives with seems a fair trade-off (cherry picked from commit 3a8fded5db91dad3d34f6dfe6184aca583a78440) IJ-CR-195627 GitOrigin-RevId: 0a92cad5b21687318d726fbc4bb7647f4afcb97c --- fleet/rpc/api-dump.txt | 22 ------------------- fleet/rpc/srcCommonMain/fleet/rpc/FleetApi.kt | 4 ++++ .../fleet/rpc/client/FleetClient.kt | 2 ++ .../fleet/rpc/client/RpcClientException.kt | 18 ++++++++------- .../platform-impl/exposed-third-party-api.txt | 1 - .../shared/exposed-third-party-api.txt | 3 +-- .../monorepo/exposed-third-party-api.txt | 1 + 7 files changed, 18 insertions(+), 33 deletions(-) diff --git a/fleet/rpc/api-dump.txt b/fleet/rpc/api-dump.txt index 2373a102ebdc..e71232556f93 100644 --- a/fleet/rpc/api-dump.txt +++ b/fleet/rpc/api-dump.txt @@ -1,60 +1,38 @@ fleet.rpc.RemoteApi fleet.rpc.RemoteApiDescriptor -- a:call(fleet.rpc.RemoteApi,java.lang.String,java.lang.Object[],kotlin.coroutines.Continuation):java.lang.Object -- a:clientStub(kotlin.jvm.functions.Function3):fleet.rpc.RemoteApi -- a:getApiFqn():java.lang.String -- a:getSignature(java.lang.String):fleet.rpc.RpcSignature @:fleet.rpc.Rpc - java.lang.annotation.Annotation f:fleet.rpc.client.DurableKt - sf:durable(Z,kotlin.jvm.functions.Function2,kotlin.coroutines.Continuation):java.lang.Object - bs:durable$default(Z,kotlin.jvm.functions.Function2,kotlin.coroutines.Continuation,I,java.lang.Object):java.lang.Object -f:fleet.rpc.client.FleetClientKt -- sf:fleetClient(fleet.rpc.client.ClientId,fleet.rpc.core.TransportFactory,Z,fleet.util.async.DelayStrategy,fleet.rpc.client.RpcInterceptor,java.lang.String):fleet.util.async.Resource -- bs:fleetClient$default(fleet.rpc.client.ClientId,fleet.rpc.core.TransportFactory,Z,fleet.util.async.DelayStrategy,fleet.rpc.client.RpcInterceptor,java.lang.String,I,java.lang.Object):fleet.util.async.Resource -- sf:proxy(fleet.rpc.client.FleetClient,fleet.rpc.RemoteApiDescriptor,fleet.util.UID,fleet.rpc.core.InstanceId):fleet.rpc.RemoteApi f:fleet.rpc.client.RemoteIsCancelledException - fleet.rpc.client.RpcClientException - kotlinx.coroutines.CopyableThrowable -- (java.lang.String,java.lang.Throwable):V - createCopy():fleet.rpc.client.RemoteIsCancelledException f:fleet.rpc.client.RouteClosedException - fleet.rpc.client.RpcClientException - kotlinx.coroutines.CopyableThrowable -- (fleet.util.UID,java.lang.String,java.lang.Throwable):V -- b:(fleet.util.UID,java.lang.String,java.lang.Throwable,I,kotlin.jvm.internal.DefaultConstructorMarker):V - createCopy():fleet.rpc.client.RouteClosedException -- f:getRoute():fleet.util.UID f:fleet.rpc.client.RpcCausalityTimeout - fleet.rpc.client.RpcClientException - kotlinx.coroutines.CopyableThrowable -- (java.lang.String,java.lang.Throwable):V - createCopy():fleet.rpc.client.RpcCausalityTimeout f:fleet.rpc.client.RpcClientDisconnectedException - fleet.rpc.client.RpcClientException - kotlinx.coroutines.CopyableThrowable -- (java.lang.String,java.lang.Throwable):V - createCopy():fleet.rpc.client.RpcClientDisconnectedException a:fleet.rpc.client.RpcClientException - java.lang.RuntimeException -- (java.lang.String,java.lang.Throwable):V f:fleet.rpc.client.RpcServiceNotReady - fleet.rpc.client.RpcClientException - kotlinx.coroutines.CopyableThrowable -- (fleet.rpc.core.RpcMessage$CallRequest,java.lang.Throwable):V -- b:(fleet.rpc.core.RpcMessage$CallRequest,java.lang.Throwable,I,kotlin.jvm.internal.DefaultConstructorMarker):V - createCopy():fleet.rpc.client.RpcServiceNotReady f:fleet.rpc.client.RpcTimeoutException - fleet.rpc.client.RpcClientException - kotlinx.coroutines.CopyableThrowable -- (java.lang.String,java.lang.Throwable):V -- b:(java.lang.String,java.lang.Throwable,I,kotlin.jvm.internal.DefaultConstructorMarker):V - createCopy():fleet.rpc.client.RpcTimeoutException - f:getMsg():java.lang.String f:fleet.rpc.client.UnresolvedServiceException - fleet.rpc.client.RpcClientException - kotlinx.coroutines.CopyableThrowable -- (fleet.rpc.core.InstanceId,java.lang.Throwable):V -- b:(fleet.rpc.core.InstanceId,java.lang.Throwable,I,kotlin.jvm.internal.DefaultConstructorMarker):V - createCopy():fleet.rpc.client.UnresolvedServiceException -- f:getServiceId():fleet.rpc.core.InstanceId diff --git a/fleet/rpc/srcCommonMain/fleet/rpc/FleetApi.kt b/fleet/rpc/srcCommonMain/fleet/rpc/FleetApi.kt index f8251e43a2b7..4d3d87a51284 100644 --- a/fleet/rpc/srcCommonMain/fleet/rpc/FleetApi.kt +++ b/fleet/rpc/srcCommonMain/fleet/rpc/FleetApi.kt @@ -56,9 +56,13 @@ data class ParameterDescriptor(val parameterName: String, val parameterKind: Rem data class RpcSignature(val methodName: String, val parameters: Array, val returnType: RemoteKind) interface RemoteApiDescriptor> { + @ApiStatus.Internal fun getSignature(methodName: String): RpcSignature + @ApiStatus.Internal fun clientStub(proxy: suspend (String, Array) -> Any?): T + @ApiStatus.Internal fun getApiFqn(): String + @ApiStatus.Internal suspend fun call(impl: T, methodName: String, args: Array): Any? } diff --git a/fleet/rpc/srcCommonMain/fleet/rpc/client/FleetClient.kt b/fleet/rpc/srcCommonMain/fleet/rpc/client/FleetClient.kt index fa56bd0aa9cf..4c7715f0a53c 100644 --- a/fleet/rpc/srcCommonMain/fleet/rpc/client/FleetClient.kt +++ b/fleet/rpc/srcCommonMain/fleet/rpc/client/FleetClient.kt @@ -59,9 +59,11 @@ class FleetClient internal constructor( } } +@ApiStatus.Internal fun > FleetClient.proxy(remoteApiDescriptor: RemoteApiDescriptor, route: UID, instanceId: InstanceId): A = asServiceProxy().proxy(remoteApiDescriptor, route, instanceId) +@ApiStatus.Internal fun fleetClient( clientId: ClientId, transportFactory: FleetTransportFactory, diff --git a/fleet/rpc/srcCommonMain/fleet/rpc/client/RpcClientException.kt b/fleet/rpc/srcCommonMain/fleet/rpc/client/RpcClientException.kt index 566618123e12..695ed019848d 100644 --- a/fleet/rpc/srcCommonMain/fleet/rpc/client/RpcClientException.kt +++ b/fleet/rpc/srcCommonMain/fleet/rpc/client/RpcClientException.kt @@ -5,18 +5,20 @@ import fleet.rpc.core.InstanceId import fleet.rpc.core.RpcMessage import fleet.util.UID import kotlinx.coroutines.CopyableThrowable +import org.jetbrains.annotations.ApiStatus /** * Base class for all exceptions that will be retried by [durable] * */ -abstract class RpcClientException(message: String?, cause: Throwable?) : RuntimeException(message, cause) +abstract class RpcClientException @ApiStatus.Internal constructor(message: String?, cause: Throwable?) : RuntimeException(message, cause) /** * Thrown when the remote service designated by [route] is offline (maybe temporarily). * * see [RpcClientException] * */ -class RouteClosedException(val route: UID, message: String, cause: Throwable? = null) + +class RouteClosedException @ApiStatus.Internal constructor(@ApiStatus.Internal val route: UID, message: String, cause: Throwable? = null) : RpcClientException(message, cause), CopyableThrowable { @@ -30,7 +32,7 @@ class RouteClosedException(val route: UID, message: String, cause: Throwable? = * * see [RpcClientException] * */ -class RpcTimeoutException(val msg: String, cause: Throwable? = null) +class RpcTimeoutException @ApiStatus.Internal constructor(val msg: String, cause: Throwable? = null) : RpcClientException(msg, cause), CopyableThrowable { override fun createCopy(): RpcTimeoutException { @@ -38,7 +40,7 @@ class RpcTimeoutException(val msg: String, cause: Throwable? = null) } } -class RpcServiceNotReady(private val req: RpcMessage.CallRequest, cause: Throwable? = null) +class RpcServiceNotReady @ApiStatus.Internal constructor(private val req: RpcMessage.CallRequest, cause: Throwable? = null) : RpcClientException("Service not ready: ${req.service}$${req.method}", cause), CopyableThrowable { override fun createCopy(): RpcServiceNotReady { @@ -46,7 +48,7 @@ class RpcServiceNotReady(private val req: RpcMessage.CallRequest, cause: Throwab } } -class UnresolvedServiceException(val serviceId: InstanceId, cause: Throwable? = null) +class UnresolvedServiceException @ApiStatus.Internal constructor(@ApiStatus.Internal val serviceId: InstanceId, cause: Throwable? = null) : RpcClientException("Service not found: ${serviceId}", cause), CopyableThrowable { override fun createCopy(): UnresolvedServiceException { @@ -59,7 +61,7 @@ class UnresolvedServiceException(val serviceId: InstanceId, cause: Throwable? = * * see [RpcClientException] * */ -class RpcClientDisconnectedException(reason: String?, cause: Throwable?) +class RpcClientDisconnectedException @ApiStatus.Internal constructor(reason: String?, cause: Throwable?) : RpcClientException(reason, cause), CopyableThrowable { override fun createCopy(): RpcClientDisconnectedException { @@ -67,7 +69,7 @@ class RpcClientDisconnectedException(reason: String?, cause: Throwable?) } } -class RpcCausalityTimeout(msg: String?, cause: Throwable?) +class RpcCausalityTimeout @ApiStatus.Internal constructor(msg: String?, cause: Throwable?) : RpcClientException(msg, cause), CopyableThrowable { override fun createCopy(): RpcCausalityTimeout { @@ -80,7 +82,7 @@ class RpcCausalityTimeout(msg: String?, cause: Throwable?) * * see [RpcClientException] * */ -class RemoteIsCancelledException(msg: String?, cause: Throwable?) +class RemoteIsCancelledException @ApiStatus.Internal constructor(msg: String?, cause: Throwable?) : RpcClientException(msg, cause), CopyableThrowable { override fun createCopy(): RemoteIsCancelledException { diff --git a/platform/platform-impl/exposed-third-party-api.txt b/platform/platform-impl/exposed-third-party-api.txt index f4111059df4e..216258270848 100644 --- a/platform/platform-impl/exposed-third-party-api.txt +++ b/platform/platform-impl/exposed-third-party-api.txt @@ -6,7 +6,6 @@ com/google/gson/reflect/TypeToken com/google/gson/stream/JsonToken com/intellij/util/ui/MenuItemLayoutHelper com/intellij/util/ui/MenuItemLayoutHelper$LayoutResult -fleet/util/UID io/netty/buffer/ByteBuf it/unimi/dsi/fastutil/longs/Long2ObjectMap it/unimi/dsi/fastutil/longs/Long2ObjectOpenHashMap diff --git a/platform/project/shared/exposed-third-party-api.txt b/platform/project/shared/exposed-third-party-api.txt index ab247f5c3451..bd81797510c2 100644 --- a/platform/project/shared/exposed-third-party-api.txt +++ b/platform/project/shared/exposed-third-party-api.txt @@ -1,5 +1,4 @@ -fleet/util/UID kotlinx/serialization/descriptors/SerialDescriptor kotlinx/serialization/encoding/Decoder kotlinx/serialization/encoding/Encoder -kotlinx/serialization/internal/GeneratedSerializer \ No newline at end of file +kotlinx/serialization/internal/GeneratedSerializer diff --git a/platform/testFramework/monorepo/exposed-third-party-api.txt b/platform/testFramework/monorepo/exposed-third-party-api.txt index 084e7e5013e5..d11c39cea53f 100644 --- a/platform/testFramework/monorepo/exposed-third-party-api.txt +++ b/platform/testFramework/monorepo/exposed-third-party-api.txt @@ -1,3 +1,4 @@ +fleet/util/UID java/awt/* java/awt/color/ColorSpace java/awt/datatransfer/*