Skip to content

Fix StaticCache::getData() returning true on empty cache#908

Merged
ahcorde merged 1 commit intoros2:rollingfrom
PavelGuzenfeld:fix/static-cache-getdata
Mar 24, 2026
Merged

Fix StaticCache::getData() returning true on empty cache#908
ahcorde merged 1 commit intoros2:rollingfrom
PavelGuzenfeld:fix/static-cache-getdata

Conversation

@PavelGuzenfeld
Copy link
Contributor

Summary

Fixes #769

StaticCache::getData() unconditionally returned true even when no data had been inserted via insertData(). This caused callers to read uninitialized TransformStorage, leading to incorrect transform data.

Changes:

  • Add a populated_ flag to StaticCache that tracks whether insertData() has been called
  • getData() now returns false with TF2_LOOKUP_ERROR when the cache is empty
  • clearList() resets the populated_ flag
  • getListLength() returns 0 when empty (was hardcoded to 1)
  • getParent() returns 0 when empty

Test plan

  • Full tf2 test suite: 12/12 pass (100%)
  • test_static_cache_unittest passes — existing tests for populated cache still work
  • test_cache_unittest passes — dynamic cache unaffected
  • All linters pass (copyright, cppcheck, cpplint, uncrustify, xmllint)

@PavelGuzenfeld PavelGuzenfeld force-pushed the fix/static-cache-getdata branch from 44a586f to 35576ea Compare March 21, 2026 21:13
@christophebedard
Copy link
Member

Thank you for the PR! Please see my note here: ros2/rclcpp#3109 (comment)

@PavelGuzenfeld
Copy link
Contributor Author

Thanks for the review!

AI disclosure: This PR was authored with the assistance of Claude Opus (Anthropic) as a generative AI coding tool. I have reviewed and validated the changes.

Branch target: Retargeting to rolling now.

@PavelGuzenfeld PavelGuzenfeld changed the base branch from jazzy to rolling March 22, 2026 06:04
StaticCache::getData() unconditionally returned true even when no data
had been inserted, causing callers to read uninitialized storage.

Add a populated_ flag that tracks whether insertData() has been called.
getData() now returns false with an appropriate error when the cache is
empty. Also fix clearList() to reset the flag and getListLength() to
return 0 when empty.

Fixes ros2#769

Signed-off-by: Pavel Guzenfeld <me@pavelguzenfeld.com>
Signed-off-by: Pavel Guzenfeld <pavelguzenfeld@gmail.com>
@PavelGuzenfeld PavelGuzenfeld force-pushed the fix/static-cache-getdata branch from 35576ea to 2371ec4 Compare March 22, 2026 06:22
@PavelGuzenfeld
Copy link
Contributor Author

Rebased onto rolling as requested. The diff is now clean (1 commit, 2 files changed).

The bug (reported in #769) also affects jazzy and humble. Would appreciate a backport to those distros once this is merged into rolling.

@ahcorde
Copy link
Contributor

ahcorde commented Mar 23, 2026

Pulls: #908
Gist: https://gist.githubusercontent.com/ahcorde/9f47435b3f85183e00bd8ae5319e89d4/raw/35984ecda60d3b83a5eee6316b9e7e50d9406472/ros2.repos
BUILD args: --packages-above-and-dependencies tf2
TEST args: --packages-above tf2
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/18615

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

@ahcorde ahcorde merged commit dad9b85 into ros2:rolling Mar 24, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tf2::StaticCache::getData() Returns true Even When Cache is Empty or Timestamp Mismatches

3 participants