Skip to content

Conversation

swankjesse
Copy link
Collaborator

Okio was broken when running on Kotlin before 2.1.20. The failure mode was too severe - a crash at runtime! And this is for code that worked just fine on Kotlin 2.0.x.

java.lang.NoSuchMethodError: 'kotlin.time.Clock kotlin.internal.PlatformImplementations.getSystemClock()'
at kotlin.time.InstantJvmKt.<clinit>(InstantJvm.kt:12)
at kotlin.time.Clock$System.now(Clock.kt:60)
at kotlinx.datetime.Clock$System.now(DeprecatedClock.kt:89)
at okio.fakefilesystem.-Time.defaultClockNowMillis_delegate$lambda$2(FileMetadataCommon.kt:70)
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
at okio.fakefilesystem.-Time.getDefaultClockNowMillis(FileMetadataCommon.kt:65)
at okio.fakefilesystem.FakeFileSystem.<init>(FakeFileSystem.kt:72)

The failure would occur anywhere we were running Okio's FakeFileSystem inside a Gradle plugin.

With this change FakeFileSystem works inside a Gradle plugin, even if the runtime Kotlin version doesn't have
kotlin.time.Clock.

Okio was broken when running on Kotlin before 2.1.20.
The failure mode was too severe - a crash at runtime!
And this is for code that worked just fine on Kotlin 2.0.x.

    java.lang.NoSuchMethodError: 'kotlin.time.Clock kotlin.internal.PlatformImplementations.getSystemClock()'
	at kotlin.time.InstantJvmKt.<clinit>(InstantJvm.kt:12)
	at kotlin.time.Clock$System.now(Clock.kt:60)
	at kotlinx.datetime.Clock$System.now(DeprecatedClock.kt:89)
	at okio.fakefilesystem.-Time.defaultClockNowMillis_delegate$lambda$2(FileMetadataCommon.kt:70)
	at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
	at okio.fakefilesystem.-Time.getDefaultClockNowMillis(FileMetadataCommon.kt:65)
	at okio.fakefilesystem.FakeFileSystem.<init>(FakeFileSystem.kt:72)

The failure would occur anywhere we were running Okio's
FakeFileSystem inside a Gradle plugin.

With this change FakeFileSystem works inside a Gradle plugin,
even if the runtime Kotlin version doesn't have
kotlin.time.Clock.
@swankjesse swankjesse merged commit a416091 into master Jul 2, 2025
11 checks passed
@swankjesse swankjesse deleted the jwilson.0701.restore_compat branch July 2, 2025 00:09
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.

4 participants