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
  • Loading branch information
sandwwraith authored and qodana-bot committed Jan 9, 2023
1 parent a1894ed commit 0b4f534
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
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,28 @@
// 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 0b4f534

Please sign in to comment.