Skip to main content

Default parameters without JvmOverloads

DiagnosticDEFAULT_PARAMETERS_WITHOUT_JVM_OVERLOADS
Default severityError
Applies toJVM compilations only
Gradle propertydefaultParametersWithoutJvmOverloads
Exemption@IntentionallyWithoutJvmOverloads

What it reports​

Functions and constructors in the public API with at least one default parameter value and no @JvmOverloads.

public fun openSocket(
host: String,
port: Int = 80,
timeout: Int = 30,
) { }

Rationale​

Without @JvmOverloads, Java callers must pass every argument. The generated overloads let them use the defaults.

Don't​

public fun connect(
host: String,
port: Int = 80,
timeout: Int = 30,
) { }

Do​

@JvmOverloads
public fun connect(
host: String,
port: Int = 80,
timeout: Int = 30,
) { }

Notes​

The check excludes:

  • Abstract functions, interface members, and annotation class constructors.
  • suspend functions and members of value classes.
  • Overrides and @JvmSynthetic declarations.
  • @PublishedApi internal declarations.

Exemption​

If this is intended, apply @IntentionallyWithoutJvmOverloads to the function or constructor.

Use the exemption when the declaration is part of the API design or must stay for backwards compatibility.

public class ConnectionConfig
@IntentionallyWithoutJvmOverloads(
description = "Kotlin-only function. " +
"Java callers are expected to use the builder instead.",
reason = ExemptionReason.IGNORE_JAVA_INTEROP,
)
public fun connect(
host: String,
port: Int = 80,
timeout: Int = 30,
builder: ConnectionConfig.() -> Unit,
) { }

Configuration​

build.gradle.kts
apiWatchdog {
javaInterop {
defaultParametersWithoutJvmOverloads = WatchdogSeverity.ERROR
}
}

javaInterop { enabled = false } disables all Java interop checks.

For a direct compiler call:

-P plugin:org.jetbrains.kotlinx.library.api.watchdog:diagnosticSeverity=DEFAULT_PARAMETERS_WITHOUT_JVM_OVERLOADS:error