From 6a0d1ac462da3dbf5e1553ccfdcd2b9d181822ea Mon Sep 17 00:00:00 2001 From: Bogdan Drutu Date: Sun, 6 Jul 2025 05:57:17 -0700 Subject: [PATCH] Document that changing pcommon.Map invalidates Value references Signed-off-by: Bogdan Drutu --- .chloggen/document-13073.yaml | 25 +++++++++++++++++++++++++ pdata/pcommon/map.go | 6 ++++-- 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 .chloggen/document-13073.yaml diff --git a/.chloggen/document-13073.yaml b/.chloggen/document-13073.yaml new file mode 100644 index 00000000000..21a35445aba --- /dev/null +++ b/.chloggen/document-13073.yaml @@ -0,0 +1,25 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) +component: pdata + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Document that changing pcommon.Map (Remove/removeIf/Put*) invalidates Value references obtained via Get. + +# One or more tracking issues or pull requests related to the change +issues: [13073] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [api] diff --git a/pdata/pcommon/map.go b/pdata/pcommon/map.go index ed71f9b410d..89b60e031d9 100644 --- a/pdata/pcommon/map.go +++ b/pdata/pcommon/map.go @@ -55,12 +55,14 @@ func (m Map) EnsureCapacity(capacity int) { copy(*m.getOrig(), oldOrig) } -// Get returns the Value associated with the key and true. Returned +// Get returns the Value associated with the key and true. The returned // Value is not a copy, it is a reference to the value stored in this map. // It is allowed to modify the returned value using Value.Set* functions. // Such modification will be applied to the value stored in this map. +// Accessing the returned value after modifying the underlying map +// (removing or adding new values) is an undefined behavior. // -// If the key does not exist returns a zero-initialized KeyValue and false. +// If the key does not exist, returns a zero-initialized KeyValue and false. // Calling any functions on the returned invalid instance may cause a panic. func (m Map) Get(key string) (Value, bool) { for i := range *m.getOrig() {