Skip to content
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

Fix public APIs for kotlin.time.Duration #8355

Merged
merged 4 commits into from
Apr 15, 2024

Conversation

swankjesse
Copy link
Member

Use this as our preferred API for accepting a duration in OkHttpClient and CacheControl.

Also hide these functions from the Java API.

Use this as our preferred API for accepting a duration in
OkHttpClient and CacheControl.

Also hide these functions from the Java API.
maxAge: Int,
timeUnit: DurationUnit,
) = commonMaxAge(maxAge, timeUnit)
@JvmSynthetic // Don't expose @JvmInline types in the Java API.
Copy link
Member

Choose a reason for hiding this comment

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

You shouldn't need any of these annotations as functions accepting value types should already have their names mangled to include a hypen which is an invalid character in Java method names. The API dump should confirm.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

) = commonMaxAge(maxAge, timeUnit)
@JvmSynthetic // Don't expose @JvmInline types in the Java API.
fun maxAge(maxAge: Duration) = apply {
require(maxAge.inWholeSeconds >= 0) { "maxAge < 0: ${maxAge.inWholeSeconds}" }
Copy link
Member

Choose a reason for hiding this comment

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

If you do

Suggested change
require(maxAge.inWholeSeconds >= 0) { "maxAge < 0: ${maxAge.inWholeSeconds}" }
require(!maxAge.isNegative()) { "maxAge < 0: ${maxAge.inWholeSeconds}" }

you avoid having to do an internal conversion solely to perform the check

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed to call inWholeSeconds once.

* precision; finer precision will be lost.
*/
@ExperimentalOkHttpApi
Copy link
Member Author

Choose a reason for hiding this comment

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

No longer experimental!

maxAge: Int,
timeUnit: DurationUnit,
) = commonMaxAge(maxAge, timeUnit)
@JvmSynthetic // Don't expose @JvmInline types in the Java API.
Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

) = commonMaxAge(maxAge, timeUnit)
@JvmSynthetic // Don't expose @JvmInline types in the Java API.
fun maxAge(maxAge: Duration) = apply {
require(maxAge.inWholeSeconds >= 0) { "maxAge < 0: ${maxAge.inWholeSeconds}" }
Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed to call inWholeSeconds once.

@swankjesse swankjesse merged commit 06a0529 into master Apr 15, 2024
20 checks passed
@swankjesse swankjesse deleted the jwilson.0409.kotlinduration branch April 15, 2024 13:41
@madd-44

This comment was marked as off-topic.

@madd-44

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants