Skip to content

Commit

Permalink
Remove deprecated declarations from runtime (#1260)
Browse files Browse the repository at this point in the history
* Remove deprecated functions from Decoder (1.4.30 plugin required)

* Adapt exception constructors for coroutines stacktrace recovery (1.4.20 plugin required)

* Add space dev repo to integration test

* Ignore tests that fail on LegacyJS due to missing commit in M1
  • Loading branch information
sandwwraith authored Dec 24, 2020
1 parent 6357dea commit 7bf5119
Show file tree
Hide file tree
Showing 16 changed files with 76 additions and 57 deletions.
8 changes: 0 additions & 8 deletions core/api/kotlinx-serialization-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,9 @@ public abstract class kotlinx/serialization/encoding/AbstractDecoder : kotlinx/s
public final fun decodeLongElement (Lkotlinx/serialization/descriptors/SerialDescriptor;I)J
public fun decodeNotNullMark ()Z
public fun decodeNull ()Ljava/lang/Void;
public synthetic fun decodeNullableSerializableElement (Lkotlinx/serialization/descriptors/SerialDescriptor;ILkotlinx/serialization/DeserializationStrategy;)Ljava/lang/Object;
public final fun decodeNullableSerializableElement (Lkotlinx/serialization/descriptors/SerialDescriptor;ILkotlinx/serialization/DeserializationStrategy;Ljava/lang/Object;)Ljava/lang/Object;
public fun decodeNullableSerializableValue (Lkotlinx/serialization/DeserializationStrategy;)Ljava/lang/Object;
public fun decodeSequentially ()Z
public synthetic fun decodeSerializableElement (Lkotlinx/serialization/descriptors/SerialDescriptor;ILkotlinx/serialization/DeserializationStrategy;)Ljava/lang/Object;
public final fun decodeSerializableElement (Lkotlinx/serialization/descriptors/SerialDescriptor;ILkotlinx/serialization/DeserializationStrategy;Ljava/lang/Object;)Ljava/lang/Object;
public fun decodeSerializableValue (Lkotlinx/serialization/DeserializationStrategy;)Ljava/lang/Object;
public fun decodeSerializableValue (Lkotlinx/serialization/DeserializationStrategy;Ljava/lang/Object;)Ljava/lang/Object;
Expand Down Expand Up @@ -382,10 +380,8 @@ public abstract interface class kotlinx/serialization/encoding/CompositeDecoder
public abstract fun decodeFloatElement (Lkotlinx/serialization/descriptors/SerialDescriptor;I)F
public abstract fun decodeIntElement (Lkotlinx/serialization/descriptors/SerialDescriptor;I)I
public abstract fun decodeLongElement (Lkotlinx/serialization/descriptors/SerialDescriptor;I)J
public abstract synthetic fun decodeNullableSerializableElement (Lkotlinx/serialization/descriptors/SerialDescriptor;ILkotlinx/serialization/DeserializationStrategy;)Ljava/lang/Object;
public abstract fun decodeNullableSerializableElement (Lkotlinx/serialization/descriptors/SerialDescriptor;ILkotlinx/serialization/DeserializationStrategy;Ljava/lang/Object;)Ljava/lang/Object;
public abstract fun decodeSequentially ()Z
public abstract synthetic fun decodeSerializableElement (Lkotlinx/serialization/descriptors/SerialDescriptor;ILkotlinx/serialization/DeserializationStrategy;)Ljava/lang/Object;
public abstract fun decodeSerializableElement (Lkotlinx/serialization/descriptors/SerialDescriptor;ILkotlinx/serialization/DeserializationStrategy;Ljava/lang/Object;)Ljava/lang/Object;
public abstract fun decodeShortElement (Lkotlinx/serialization/descriptors/SerialDescriptor;I)S
public abstract fun decodeStringElement (Lkotlinx/serialization/descriptors/SerialDescriptor;I)Ljava/lang/String;
Expand All @@ -400,10 +396,8 @@ public final class kotlinx/serialization/encoding/CompositeDecoder$Companion {

public final class kotlinx/serialization/encoding/CompositeDecoder$DefaultImpls {
public static fun decodeCollectionSize (Lkotlinx/serialization/encoding/CompositeDecoder;Lkotlinx/serialization/descriptors/SerialDescriptor;)I
public static synthetic fun decodeNullableSerializableElement (Lkotlinx/serialization/encoding/CompositeDecoder;Lkotlinx/serialization/descriptors/SerialDescriptor;ILkotlinx/serialization/DeserializationStrategy;)Ljava/lang/Object;
public static synthetic fun decodeNullableSerializableElement$default (Lkotlinx/serialization/encoding/CompositeDecoder;Lkotlinx/serialization/descriptors/SerialDescriptor;ILkotlinx/serialization/DeserializationStrategy;Ljava/lang/Object;ILjava/lang/Object;)Ljava/lang/Object;
public static fun decodeSequentially (Lkotlinx/serialization/encoding/CompositeDecoder;)Z
public static synthetic fun decodeSerializableElement (Lkotlinx/serialization/encoding/CompositeDecoder;Lkotlinx/serialization/descriptors/SerialDescriptor;ILkotlinx/serialization/DeserializationStrategy;)Ljava/lang/Object;
public static synthetic fun decodeSerializableElement$default (Lkotlinx/serialization/encoding/CompositeDecoder;Lkotlinx/serialization/descriptors/SerialDescriptor;ILkotlinx/serialization/DeserializationStrategy;Ljava/lang/Object;ILjava/lang/Object;)Ljava/lang/Object;
}

Expand Down Expand Up @@ -978,11 +972,9 @@ public abstract class kotlinx/serialization/internal/TaggedDecoder : kotlinx/ser
public final fun decodeLongElement (Lkotlinx/serialization/descriptors/SerialDescriptor;I)J
public fun decodeNotNullMark ()Z
public final fun decodeNull ()Ljava/lang/Void;
public synthetic fun decodeNullableSerializableElement (Lkotlinx/serialization/descriptors/SerialDescriptor;ILkotlinx/serialization/DeserializationStrategy;)Ljava/lang/Object;
public final fun decodeNullableSerializableElement (Lkotlinx/serialization/descriptors/SerialDescriptor;ILkotlinx/serialization/DeserializationStrategy;Ljava/lang/Object;)Ljava/lang/Object;
public fun decodeNullableSerializableValue (Lkotlinx/serialization/DeserializationStrategy;)Ljava/lang/Object;
public fun decodeSequentially ()Z
public synthetic fun decodeSerializableElement (Lkotlinx/serialization/descriptors/SerialDescriptor;ILkotlinx/serialization/DeserializationStrategy;)Ljava/lang/Object;
public final fun decodeSerializableElement (Lkotlinx/serialization/descriptors/SerialDescriptor;ILkotlinx/serialization/DeserializationStrategy;Ljava/lang/Object;)Ljava/lang/Object;
public fun decodeSerializableValue (Lkotlinx/serialization/DeserializationStrategy;)Ljava/lang/Object;
protected fun decodeSerializableValue (Lkotlinx/serialization/DeserializationStrategy;Ljava/lang/Object;)Ljava/lang/Object;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,22 @@ public open class SerializationException : IllegalArgumentException {
* Thrown when [KSerializer] did not receive property from [Decoder], and this property was not optional.
*/
@PublishedApi
internal class MissingFieldException(fieldName: String) : // TODO: add (message, cause) ctor after 1.4.20 for coroutines stacktrace recovery
SerializationException("Field '$fieldName' is required, but it was missing")
internal class MissingFieldException
// This constructor is used by coroutines exception recovery
internal constructor(message: String?, cause: Throwable?) : SerializationException(message, cause) {
// This constructor is used by the generated serializers
constructor(fieldName: String) : this("Field '$fieldName' is required, but it was missing", null)
}

/**
* Thrown when [KSerializer] received unknown property index from [CompositeDecoder.decodeElementIndex].
*
* This exception means that data schema has changed in backwards-incompatible way.
*/
@PublishedApi // TODO: add (message, cause) ctor after 1.4.20 for coroutines stacktrace recovery
internal class UnknownFieldException(index: Int) : SerializationException("An unknown field for index $index")
@PublishedApi
internal class UnknownFieldException
// This constructor is used by coroutines exception recovery
internal constructor(message: String?) : SerializationException(message) {
// This constructor is used by the generated serializers
constructor(index: Int) : this("An unknown field for index $index")
}
19 changes: 0 additions & 19 deletions core/commonMain/src/kotlinx/serialization/encoding/Decoding.kt
Original file line number Diff line number Diff line change
Expand Up @@ -495,25 +495,6 @@ public interface CompositeDecoder {
deserializer: DeserializationStrategy<T?>,
previousValue: T? = null
): T?

@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE", "DeprecatedCallableAddReplaceWith")
@kotlin.internal.LowPriorityInOverloadResolution
@Deprecated(decodeMethodDeprecated, level = DeprecationLevel.HIDDEN)
public fun <T : Any?> decodeSerializableElement(
descriptor: SerialDescriptor,
i: Int, // renamed from index to be called even with LowPriority
deserializer: DeserializationStrategy<T>
): T = decodeSerializableElement(descriptor, i, deserializer, null)

@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE", "DeprecatedCallableAddReplaceWith")
@kotlin.internal.LowPriorityInOverloadResolution
@Deprecated(decodeMethodDeprecated, level = DeprecationLevel.HIDDEN)
@OptIn(ExperimentalSerializationApi::class)
public fun <T : Any> decodeNullableSerializableElement(
descriptor: SerialDescriptor,
i: Int, // renamed from index to be called even with LowPriority
deserializer: DeserializationStrategy<T?>
): T? = decodeNullableSerializableElement(descriptor, i, deserializer, null)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ class CborReaderTest {
* decoding to [Simple] (which has the field 'a') is expected to fail.
*/
@Test
@Ignore // fixme: legacyJs will work in 1.4.30-RC
fun testIgnoreUnknownKeysFailsWhenCborDataIsMissingKeysThatArePresentInKotlinClass() {
// with maps & lists of indefinite length
assertFailsWithMessage<SerializationException>("Field 'a' is required, but it was missing") {
Expand Down
2 changes: 0 additions & 2 deletions formats/json/api/kotlinx-serialization-json.api
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,8 @@ public abstract interface class kotlinx/serialization/json/JsonDecoder : kotlinx

public final class kotlinx/serialization/json/JsonDecoder$DefaultImpls {
public static fun decodeCollectionSize (Lkotlinx/serialization/json/JsonDecoder;Lkotlinx/serialization/descriptors/SerialDescriptor;)I
public static synthetic fun decodeNullableSerializableElement (Lkotlinx/serialization/json/JsonDecoder;Lkotlinx/serialization/descriptors/SerialDescriptor;ILkotlinx/serialization/DeserializationStrategy;)Ljava/lang/Object;
public static fun decodeNullableSerializableValue (Lkotlinx/serialization/json/JsonDecoder;Lkotlinx/serialization/DeserializationStrategy;)Ljava/lang/Object;
public static fun decodeSequentially (Lkotlinx/serialization/json/JsonDecoder;)Z
public static synthetic fun decodeSerializableElement (Lkotlinx/serialization/json/JsonDecoder;Lkotlinx/serialization/descriptors/SerialDescriptor;ILkotlinx/serialization/DeserializationStrategy;)Ljava/lang/Object;
public static fun decodeSerializableValue (Lkotlinx/serialization/json/JsonDecoder;Lkotlinx/serialization/DeserializationStrategy;)Ljava/lang/Object;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class InheritanceTest {
}

@Test
fun canBeSerializedAsParent() {
fun canBeSerializedAsParent() = noLegacyJs { // fixme: legacyJs will work in 1.4.30-RC
val derived = Derived(42)
val msg = json.encodeToString(SerializableBase.serializer(), derived)
assertEquals("""{"publicState":"A","privateState":"B"}""", msg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ class JsonOptionalTests : JsonTestBase() {
}

@Test
fun testThrowMissingField() = parametrizedTest { useStreaming ->
assertFailsWithMissingField {
lenient.decodeFromString(Data.serializer(), "{b:0}", useStreaming)
fun testThrowMissingField() = noLegacyJs { // fixme: legacyJs will work in 1.4.30-RC
parametrizedTest { useStreaming ->
assertFailsWithMissingField {
lenient.decodeFromString(Data.serializer(), "{b:0}", useStreaming)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,51 @@ class JsonParserFailureModesTest : JsonTestBase() {
)

@Test
fun testFailureModes() = parametrizedTest {
assertFailsWith<JsonDecodingException> { default.decodeFromString(Holder.serializer(), """{"id": "}""", it) }
assertFailsWith<JsonDecodingException> { default.decodeFromString(Holder.serializer(), """{"id": ""}""", it) }
assertFailsWith<JsonDecodingException> { default.decodeFromString(Holder.serializer(), """{"id":a}""", it) }
assertFailsWith<JsonDecodingException> { default.decodeFromString(Holder.serializer(), """{"id":2.0}""", it) }
assertFailsWith<JsonDecodingException> { default.decodeFromString(Holder.serializer(), """{"id2":2}""", it) }
assertFailsWith<JsonDecodingException> { default.decodeFromString(Holder.serializer(), """{"id"}""", it) }
assertFailsWith<JsonDecodingException> { default.decodeFromString(Holder.serializer(), """{"id}""", it) }
assertFailsWith<JsonDecodingException> { default.decodeFromString(Holder.serializer(), """{"i}""", it) }
assertFailsWith<JsonDecodingException> { default.decodeFromString(Holder.serializer(), """{"}""", it) }
assertFailsWithMissingField { default.decodeFromString(Holder.serializer(), """{}""", it) }
assertFailsWith<JsonDecodingException> { default.decodeFromString(Holder.serializer(), """{""", it) }
assertFailsWith<JsonDecodingException> { default.decodeFromString(Holder.serializer(), """}""", it) }
assertFailsWith<JsonDecodingException> { default.decodeFromString(Holder.serializer(), """{""", it) }
fun testFailureModes() = noLegacyJs { // fixme: legacyJs will work in 1.4.30-RC
parametrizedTest {
assertFailsWith<JsonDecodingException> {
default.decodeFromString(
Holder.serializer(),
"""{"id": "}""",
it
)
}
assertFailsWith<JsonDecodingException> {
default.decodeFromString(
Holder.serializer(),
"""{"id": ""}""",
it
)
}
assertFailsWith<JsonDecodingException> {
default.decodeFromString(
Holder.serializer(),
"""{"id":a}""",
it
)
}
assertFailsWith<JsonDecodingException> {
default.decodeFromString(
Holder.serializer(),
"""{"id":2.0}""",
it
)
}
assertFailsWith<JsonDecodingException> {
default.decodeFromString(
Holder.serializer(),
"""{"id2":2}""",
it
)
}
assertFailsWith<JsonDecodingException> { default.decodeFromString(Holder.serializer(), """{"id"}""", it) }
assertFailsWith<JsonDecodingException> { default.decodeFromString(Holder.serializer(), """{"id}""", it) }
assertFailsWith<JsonDecodingException> { default.decodeFromString(Holder.serializer(), """{"i}""", it) }
assertFailsWith<JsonDecodingException> { default.decodeFromString(Holder.serializer(), """{"}""", it) }
assertFailsWithMissingField { default.decodeFromString(Holder.serializer(), """{}""", it) }
assertFailsWith<JsonDecodingException> { default.decodeFromString(Holder.serializer(), """{""", it) }
assertFailsWith<JsonDecodingException> { default.decodeFromString(Holder.serializer(), """}""", it) }
assertFailsWith<JsonDecodingException> { default.decodeFromString(Holder.serializer(), """{""", it) }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class JsonTreeTest : JsonTestBase() {
}

@Test
fun testReadTreeNullable() {
fun testReadTreeNullable() = noLegacyJs { // fixme: legacyJs will work in 1.4.30-RC
val tree1 = prepare("""{s:"foo", d: null}""")
val tree2 = prepare("""{s:"foo"}""")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ inline fun noJs(test: () -> Unit) {
if (!isJs()) test()
}

inline fun noLegacyJs(test: () -> Unit) {
if (!isJsLegacy()) test()
}

inline fun jvmOnly(test: () -> Unit) {
if (isJvm()) test()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class DecodeFromDynamicTest {
}

@Test
fun dynamicNullableTest() {
fun dynamicNullableTest() = noLegacyJs { // fixme: legacyJs will work in 1.4.30-RC
val dyn1 = js("""({s:"foo", d: null})""")
val dyn2 = js("""({s:"foo"})""")
val dyn3 = js("""({s:"foo", d: undefined})""")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,13 @@ class StacktraceRecoveryTest {
}

@Test
@Ignore // fixme after 1.4.20 plugin with support for new exception ctor signatures
// checks simple name because UFE is internal class
fun testUnknownFieldException() = checkRecovered("UnknownFieldException") {
val serializer = Data.serializer()
serializer.deserialize(BadDecoder())
}

@Test
@Ignore // fixme after 1.4.20 plugin with support for new exception ctor signatures
// checks simple name because MFE is internal class
fun testMissingFieldException() = checkRecovered("MissingFieldException") {
Json.decodeFromString<Data>("{}")
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#

group=org.jetbrains.kotlinx
version=1.0.1-SNAPSHOT
version=1.0.2-SNAPSHOT

kotlin.version=1.4.30-M1

Expand Down
1 change: 1 addition & 0 deletions integration-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ repositories {
mavenLocal()
mavenCentral()
maven { url 'https://dl.bintray.com/kotlin/kotlin-dev' }
maven { url "https://cache-redirector.jetbrains.com/maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" }
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }
maven { url "https://kotlin.bintray.com/kotlinx" }
}
Expand Down
2 changes: 1 addition & 1 deletion integration-test/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#

mainKotlinVersion=1.4.30-M1
mainLibVersion=1.0.1-SNAPSHOT
mainLibVersion=1.0.2-SNAPSHOT

kotlin.code.style=official
kotlin.js.compiler=both
Expand Down
1 change: 1 addition & 0 deletions integration-test/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pluginManagement {
mavenLocal()
mavenCentral()
jcenter()
maven { url "https://cache-redirector.jetbrains.com/maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" }
maven { url 'https://dl.bintray.com/kotlin/kotlin-dev' }
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }
maven { url 'https://plugins.gradle.org/m2/' }
Expand Down

0 comments on commit 7bf5119

Please sign in to comment.