Current Behavior
When using the RunCommandRequest.Builder in a Java project, the timeout(Duration) method is inaccessible. Even though the method is defined as public in Kotlin, the Java compiler cannot resolve it.
Root Cause
The timeout method uses kotlin.time.Duration as a parameter, which is a Kotlin value class (inline class).
As per Kotlin documentation, functions that use inline classes as parameters are mangled by adding a hashcode to the function name to prevent platform signature clashes and unintended overloads from Java.
Specifically, the timeout method name is transformed into something like timeout-VjEq2sY in the generated JVM bytecode. Since Java is unaware of this mangling mechanism, it cannot "see" or call the original timeout name, resulting in a compilation error for Java-based SDK consumers.
We can verify this behavior by running javap -cp sandbox-1.0.9.jar 'com.alibaba.opensandbox.sandbox.domain.models.execd.executions.RunCommandRequest$Builder' (omit some irrelevant methods):
public final class com.alibaba.opensandbox.sandbox.domain.models.execd.executions.RunCommandRequest$Builder {
public final com.alibaba.opensandbox.sandbox.domain.models.execd.executions.RunCommandRequest$Builder command(java.lang.String);
public final com.alibaba.opensandbox.sandbox.domain.models.execd.executions.RunCommandRequest$Builder timeout-BwNAW2A(kotlin.time.Duration);
public final com.alibaba.opensandbox.sandbox.domain.models.execd.executions.RunCommandRequest build();
}
Steps to Reproduce
In a Java project, attempt to use the Builder to set a timeout:
import com.alibaba.opensandbox.sandbox.domain.models.execd.executions.RunCommandRequest;
import kotlin.time.DurationKt;
import kotlin.time.DurationUnit;
public class TestRunCommandRequest {
public static void main(String[] args) {
RunCommandRequest request = RunCommandRequest.builder()
.command("ls")
.timeout(DurationKt.toDuration(5, DurationUnit.SECONDS))
.build();
}
}
The Java compiler failed to compile:
java: cannot find symbol
symbol: method timeout(long)
location: class com.alibaba.opensandbox.sandbox.domain.models.execd.executions.RunCommandRequest.Builder
Suggested Fix
To ensure seamless Java interoperability, please provide a Java-friendly overload in the Builder. Here are a few recommended options:
// Option 1: Long-based overload (standard for Java interop)
fun timeout(millis: Long?): Builder {
this.timeout = millis?.toDuration(kotlin.time.DurationUnit.MILLISECONDS)
return this
}
// Option 2: java.time.Duration (modern Java support)
fun timeout(duration: java.time.Duration?): Builder {
this.timeout = duration?.toKotlinDuration()
return this
}
Current Behavior
When using the
RunCommandRequest.Builderin a Java project, thetimeout(Duration)method is inaccessible. Even though the method is defined aspublicin Kotlin, the Java compiler cannot resolve it.Root Cause
The
timeoutmethod useskotlin.time.Durationas a parameter, which is a Kotlin value class (inline class).As per Kotlin documentation, functions that use inline classes as parameters are mangled by adding a hashcode to the function name to prevent platform signature clashes and unintended overloads from Java.
Specifically, the
timeoutmethod name is transformed into something liketimeout-VjEq2sYin the generated JVM bytecode. Since Java is unaware of this mangling mechanism, it cannot "see" or call the originaltimeoutname, resulting in a compilation error for Java-based SDK consumers.We can verify this behavior by running
javap -cp sandbox-1.0.9.jar 'com.alibaba.opensandbox.sandbox.domain.models.execd.executions.RunCommandRequest$Builder'(omit some irrelevant methods):Steps to Reproduce
In a Java project, attempt to use the
Builderto set a timeout:The Java compiler failed to compile:
Suggested Fix
To ensure seamless Java interoperability, please provide a Java-friendly overload in the
Builder. Here are a few recommended options: