Skip to content

Commit

Permalink
Skip properties from Java classes for which the getter type is unknown
Browse files Browse the repository at this point in the history
thus avoiding NPE when auto-generating external serializers.

#KT-55681 Fixed

(cherry picked from commit 0b4f534)
  • Loading branch information
sandwwraith authored and qodana-bot committed Jan 23, 2023
1 parent c8a4ba1 commit d5e97c6
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

Expand Down Expand Up @@ -74,7 +74,7 @@ internal fun serializablePropertiesForIrBackend(
if (irClass.isInternalSerializable) !it.annotations.hasAnnotation(SerializationAnnotations.serialTransientFqName)
else !DescriptorVisibilities.isPrivate(it.visibility) && ((it.isVar && !it.annotations.hasAnnotation(SerializationAnnotations.serialTransientFqName)) || primaryParamsAsProps.contains(
it
))
)) && it.getter?.returnType != null // For some reason, some properties from Java (like java.net.URL.hostAddress) do not have getter. Let's ignore them, as they never have worked properly in K1 either.

val (primaryCtorSerializableProps, bodySerializableProps) = properties
.asSequence()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM_IR

// WITH_STDLIB

import kotlinx.serialization.*
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.*
import java.net.URL


// @Serializer should do nothing if all methods are overriden
@Serializer(forClass = URL::class)
object URLSerializer : KSerializer<URL> {
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("java.net.URL", PrimitiveKind.STRING)

override fun serialize(encoder: Encoder, value: URL) {
TODO()
}

override fun deserialize(decoder: Decoder): URL {
TODO()
}
}

fun box(): String {
if (URLSerializer.descriptor.toString() != "PrimitiveDescriptor(java.net.URL)") return URLSerializer.descriptor.toString()
return "OK"
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d5e97c6

Please sign in to comment.