Skip to content

Commit

Permalink
Work around the failure of SerialDescriptor to take element names into
Browse files Browse the repository at this point in the history
account in hashCode/equals. As this is mainly relevant for reuse of
descriptor names we don't override hashcode, but are merely more strict
for equals.
  • Loading branch information
pdvrieze committed Dec 2, 2024
1 parent 38292a6 commit 214e29a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,18 @@ public class DefaultFormatCache : FormatCache() {
val canBeAttribute: Boolean
)

private data class TypeKey(val namespace: String, val descriptor: SerialDescriptor)
private data class TypeKey(val namespace: String, val descriptor: SerialDescriptor) {
override fun equals(other: Any?): Boolean {
return when {
other !is TypeKey -> false
namespace != other.namespace -> false
descriptor != other.descriptor -> false
(0 until descriptor.elementsCount).any { descriptor.getElementName(it) != other.descriptor.getElementName(it) } -> false
else -> true
}
return super.equals(other)
}
}

private companion object {
@JvmStatic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1891,11 +1891,11 @@ public class ParentInfo(

other as ParentInfo

if (descriptor != other.descriptor) return false
if (index != other.index) return false
if (overriddenSerializer != other.overriddenSerializer) return false
if (elementUseNameInfo != other.elementUseNameInfo) return false
return elementUseOutputKind == other.elementUseOutputKind
if (elementUseOutputKind != other.elementUseOutputKind) return false
return descriptor == other.descriptor
}

override fun hashCode(): Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,16 @@ public class XmlTypeDescriptor internal constructor(

other as XmlTypeDescriptor

if (serialDescriptor != other.serialDescriptor) return false
return typeNameInfo == other.typeNameInfo
return when {
typeNameInfo != other.typeNameInfo -> false
serialDescriptor != other.serialDescriptor -> false
(0 until serialDescriptor.elementsCount).any {
serialDescriptor.getElementName(it) != other.serialDescriptor.getElementName(
it
)
} -> false
else -> true
}
}

override fun hashCode(): Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,8 @@ class ElementNames254 {

@BeforeTest
fun setup() {
xml= XML {
recommended {
// TODO Remove this check once a fix exists in the library.
formatCache = FormatCache.Dummy
}
xml = XML {
recommended_0_90_2()
indent = 4
}
}
Expand Down

0 comments on commit 214e29a

Please sign in to comment.