Skip to content

🧹 [code health improvement: safe location parsing] - #243

Closed
Dor-bl wants to merge 2 commits into
mainfrom
fix/safe-location-parsing-1816635220943453478
Closed

🧹 [code health improvement: safe location parsing]#243
Dor-bl wants to merge 2 commits into
mainfrom
fix/safe-location-parsing-1816635220943453478

Conversation

@Dor-bl

@Dor-bl Dor-bl commented Aug 16, 2026

Copy link
Copy Markdown
Owner

🎯 What: Modified the Location getter in src/Appium.Net/Appium/AppiumDriver.cs to check for null values in the Appium server response and replace direct dictionary access with TryGetValue.

💡 Why: Previous implementation directly accessed dictionary keys (locationValues["altitude"]) and blindly casted the dictionary without null checks. This improved type safety ensures that missing keys return 0.0 rather than causing KeyNotFoundException and an empty payload does not cause a NullReferenceException.

Verification: Compiled the code via dotnet build Appium.Net.sln which ran successfully. Ran related Appium integration tests with dotnet test test/integration/Appium.Net.Integration.Tests.csproj --filter "FullyQualifiedName~Location" to ensure changes cause no regressions in C# execution. Requested and passed internal code review.

Result: Improved maintainability and robustness by safely fetching and converting coordinate values from the untyped Appium server JSON payload.


PR created automatically by Jules for task 1816635220943453478 started by @Dor-bl

Updated the Location property getter in AppiumDriver to use `TryGetValue`
instead of direct dictionary indexing, adding a null check, and returning
defaults if keys are missing. This prevents potential `NullReferenceException`
and `KeyNotFoundException` during location retrieval while improving overall
code robustness.
@google-labs-jules

Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copilot AI lite review requested due to automatic review settings August 16, 2026 14:55

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Improves robustness of AppiumDriver.Location parsing by making the getter resilient to missing/empty geolocation payloads returned from the Appium server, avoiding exceptions and returning a default Location instead.

Changes:

  • Added a null check for the location payload to prevent NullReferenceException when the response cannot be cast to a dictionary.
  • Replaced direct dictionary indexing with TryGetValue + 0.0 defaults to prevent KeyNotFoundException when keys are missing.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Updated the Location property getter in AppiumDriver to use `TryGetValue`
instead of direct dictionary indexing, adding a null check, and returning
defaults if keys are missing. This prevents potential `NullReferenceException`
and `KeyNotFoundException` during location retrieval while improving overall
code robustness.

Also replaced `elementToTouch.Rect` with `elementToTouch.Location` and
`elementToTouch.Size` in `ActionsChainsTest.cs` to prevent
`StaleElementReferenceException` which was occurring in CI when reading `.Rect` due to extra backend calls.

Dor-bl commented Aug 16, 2026

Copy link
Copy Markdown
Owner Author

Closing in favor of #244, which covers the same change.

Both PRs rewrite the same AppiumDriver.Location getter and the same test/integration/Android/ActionsChainsTest.cs, so only one can land. #244 is the stronger version: it caches elementToTouch.Rect in a local, whereas this PR's test change (elementToTouch.Location.X + elementToTouch.Size.Width) issues three separate property fetches instead of one.


Generated by Claude Code

@Dor-bl Dor-bl closed this Aug 16, 2026
@google-labs-jules

Copy link
Copy Markdown

Closing in favor of #244, which covers the same change.

Both PRs rewrite the same AppiumDriver.Location getter and the same test/integration/Android/ActionsChainsTest.cs, so only one can land. #244 is the stronger version: it caches elementToTouch.Rect in a local, whereas this PR's test change (elementToTouch.Location.X + elementToTouch.Size.Width) issues three separate property fetches instead of one.


Generated by Claude Code

Understood. Acknowledging that this work is now obsolete and stopping work on this task.

@Dor-bl
Dor-bl deleted the fix/safe-location-parsing-1816635220943453478 branch August 16, 2026 20:18
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