Skip to content

fix: harden ground item action reflection#1807

Merged
chsami merged 2 commits into
chsami:developmentfrom
JogOnJohn:fix/ground-item-action-reflection-hardening
Jun 25, 2026
Merged

fix: harden ground item action reflection#1807
chsami merged 2 commits into
chsami:developmentfrom
JogOnJohn:fix/ground-item-action-reflection-hardening

Conversation

@JogOnJohn

Copy link
Copy Markdown
Contributor

Summary

Defensive hardening for Microbot ground item action reflection and action resolution.

This PR does not claim that normal ground item pickup is broadly broken upstream. The intent is narrower: avoid brittle reflection/action-resolution behavior when client internals include misleading static/synthetic fields or when the requested ground action cannot be resolved cleanly.

Changes

  • Ignore static and synthetic fields during ground item action reflection discovery.
  • Accept List implementations rather than only concrete ArrayList fields.
  • Reset cached ground item action reflection discovery when the inspected class changes.
  • Avoid falling through to a default ground action when the requested action could not be resolved.
  • Stop on the first matching ground action slot instead of allowing later duplicate matches to overwrite the resolved slot.
  • Add regression coverage for static-field false positives, List implementations, cache behavior, and unresolved action handling.

Validation

  • git diff --check upstream/development...HEAD
  • ./gradlew.bat :client:compileJava --console=plain

@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a40731d7-21e2-48e4-bb71-8366e7349c9c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

Ground-item action handling was updated across reflection and interaction paths. Rs2Reflection now discovers actions from List-backed structures, centralizes cache reset, and returns an empty array when discovery fails. Rs2GroundItem and Rs2TileItemModel now validate matched actions, resolve menu actions through a shared index-to-MenuAction helper, and log stack traces through Microbot.logStackTrace. New tests add fixtures for different item shapes and verify action discovery and menu-action mapping.

Possibly related PRs

  • chsami/Microbot#1718: Both changes touch Rs2Reflection ground-item action discovery and cache invalidation.
  • chsami/Microbot#1803: Both changes adjust ground-item action-slot resolution in Rs2Reflection, Rs2GroundItem, and Rs2TileItemModel.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.45% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: hardening ground item action reflection and resolution.
Description check ✅ Passed The description is directly aligned with the reflected action-resolution and regression-test changes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@JogOnJohn JogOnJohn marked this pull request as ready for review June 25, 2026 11:09

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@runelite-client/src/main/java/net/runelite/client/plugins/microbot/api/tileitem/models/Rs2TileItemModel.java`:
- Around line 227-239: The default click path in Rs2TileItemModel currently
assumes the first ground action is at index 0, so click() can fail when
groundActions has leading null entries. Update the click("") handling to resolve
the first non-null usable action by scanning the array (matching the same lookup
behavior used for explicit actions) instead of hard-coding groundActions[0], and
keep the existing index tracking so the selected action is applied correctly.

In
`@runelite-client/src/main/java/net/runelite/client/plugins/microbot/util/reflection/Rs2Reflection.java`:
- Around line 88-95: The cache-first path in Rs2Reflection still reuses cached
fields before verifying the inspected class, so a class switch can return null
or empty results without triggering rediscovery. Update the cache keying logic
around extractWithCache and the ground item action lookup to compare the current
item/class against the cached class before using cachedOuterField and
cachedListField, and force resetGroundItemActionCache plus re-discovery whenever
the inspected class changes rather than waiting for reflection to throw.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: c9d3d9e4-e72c-4867-9883-192b9a87e685

📥 Commits

Reviewing files that changed from the base of the PR and between 262cce9 and 1c5bf88.

📒 Files selected for processing (6)
  • runelite-client/src/main/java/net/runelite/client/plugins/microbot/api/tileitem/models/Rs2TileItemModel.java
  • runelite-client/src/main/java/net/runelite/client/plugins/microbot/util/grounditem/Rs2GroundItem.java
  • runelite-client/src/main/java/net/runelite/client/plugins/microbot/util/reflection/Rs2Reflection.java
  • runelite-client/src/test/java/groundactionfixture/GroundItemActionFixture.java
  • runelite-client/src/test/java/net/runelite/client/plugins/microbot/util/grounditem/GroundItemMenuActionResolutionTest.java
  • runelite-client/src/test/java/net/runelite/client/plugins/microbot/util/reflection/Rs2ReflectionGroundItemActionsTest.java

@JogOnJohn

Copy link
Copy Markdown
Contributor Author

Addressed the CodeRabbit ground item findings in the latest push.

  • The default click("") path now scans for the first non-null ground action and preserves that action slot index.
  • Ground item action reflection cache is now keyed by the inspected item class and resets before cache reuse when the class changes.

@chsami chsami merged commit 43ed4f2 into chsami:development Jun 25, 2026
1 check passed
@JogOnJohn JogOnJohn deleted the fix/ground-item-action-reflection-hardening branch June 25, 2026 21:46
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.

2 participants