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

Zero value MapValue causes panic in Equal method #959

Closed
jar-b opened this issue Mar 18, 2024 · 1 comment · Fixed by #961
Closed

Zero value MapValue causes panic in Equal method #959

jar-b opened this issue Mar 18, 2024 · 1 comment · Fixed by #961
Labels
bug Something isn't working
Milestone

Comments

@jar-b
Copy link
Member

jar-b commented Mar 18, 2024

Module version

v1.6.1

Expected Behavior

Equal handles a nil elementType. I'm not sure if the receiver having a nil type should always return false, or if an input that also has a nil type and equivalent state should technically match.

Actual Behavior

Panic.

Steps to Reproduce

  1. Add a test case like the following to TestMapValueEqual.
    "zero-null": {
        receiver: MapValue{},
        input:    NewMapNull(StringType{}),
        expected: false,
    },
  1. Observe panic.
% go test -v ./types/basetypes/... -run=TestMapValueEqual/zero-null
=== RUN   TestMapValueEqual
=== PAUSE TestMapValueEqual
=== CONT  TestMapValueEqual
=== RUN   TestMapValueEqual/zero-null
=== PAUSE TestMapValueEqual/zero-null
=== CONT  TestMapValueEqual/zero-null
--- FAIL: TestMapValueEqual (0.00s)
    --- FAIL: TestMapValueEqual/zero-null (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
        panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x20 pc=0x104e0eba0]

goroutine 19 [running]:
testing.tRunner.func1.2({0x104f481a0, 0x1051653c0})
        /opt/homebrew/Cellar/go/1.21.7/libexec/src/testing/testing.go:1545 +0x1c4
testing.tRunner.func1()
        /opt/homebrew/Cellar/go/1.21.7/libexec/src/testing/testing.go:1548 +0x360
panic({0x104f481a0?, 0x1051653c0?})
        /opt/homebrew/Cellar/go/1.21.7/libexec/src/runtime/panic.go:914 +0x218
github.com/hashicorp/terraform-plugin-framework/types/basetypes.MapValue.Equal({0x0?, {0x0?, 0x0?}, 0x7d?}, {0x104f9cb20?, 0x14000142240?})
        /Users/jaredbaker/development/terraform-plugin-framework/types/basetypes/map_value.go:259 +0x50
github.com/hashicorp/terraform-plugin-framework/types/basetypes.TestMapValueEqual.func1(0x14000124b60)
        /Users/jaredbaker/development/terraform-plugin-framework/types/basetypes/map_value_test.go:601 +0x58
testing.tRunner(0x14000124b60, 0x14000126bc0)
        /opt/homebrew/Cellar/go/1.21.7/libexec/src/testing/testing.go:1595 +0xe8
created by testing.(*T).Run in goroutine 18
        /opt/homebrew/Cellar/go/1.21.7/libexec/src/testing/testing.go:1648 +0x33c
FAIL    github.com/hashicorp/terraform-plugin-framework/types/basetypes 0.447s
FAIL

References

Relates hashicorp/terraform-provider-aws#36437

@jar-b jar-b added the bug Something isn't working label Mar 18, 2024
@bflad bflad added this to the v1.8.0 milestone Mar 21, 2024
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants