Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Equality and hashcode are incorrectly code generated for union members with nested blobs #1146

Open
ianbotsf opened this issue Sep 5, 2024 · 0 comments
Assignees
Labels
bug This issue is a bug.

Comments

@ianbotsf
Copy link
Contributor

ianbotsf commented Sep 5, 2024

Describe the bug

Codegen for unions special-cases union members that are blobs to be handled correctly (i.e., by content, not by reference) when calculating hashcode and equality. But it does not account for union members that have nested blobs.

For example, consider DynamoDB's AttributeValue union:

sealed class AttributeValue {
    // This class is correct because the array is properly handled in equals/hashcode
    data class B(val value: ByteArray) : AttributeValue() {
        override fun hashCode(): Int {
            return value.contentHashCode()
        }

        override fun equals(other: Any?): Boolean {
            if (this === other) return true
            if (other == null || this::class != other::class) return false

            other as B

            if (!value.contentEquals(other.value)) return false

            return true
        }
    }

    // This class is correct because non-arrays don't need special handling
    data class Bool(val value: Boolean) : AttributeValue()

    // This class is incorrect because the arrays are hashed/compared by reference, not by content
    data class Bs(val value: List<ByteArray>) : AttributeValue()
}

Expected behavior

The generated code for union members that contain nested blobs should codegen equals/hashcode implementations which verify content equality, not reference equality.

Current behavior

(see above)

Steps to Reproduce

(see above)

Possible Solution

No response

Context

No response

Smithy-Kotlin version

1.3.5

Platform (JVM/JS/Native)

(any)

Operating system and version

(any)

@ianbotsf ianbotsf added the bug This issue is a bug. label Sep 5, 2024
@ianbotsf ianbotsf self-assigned this Sep 5, 2024
@ianbotsf ianbotsf added the needs-triage This issue or PR still needs to be triaged. label Sep 5, 2024
@ianbotsf ianbotsf removed the needs-triage This issue or PR still needs to be triaged. label Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug.
Projects
None yet
Development

No branches or pull requests

1 participant