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

fix: usage of Optional.orElseThrow after Map.put #2145

Merged
merged 6 commits into from
Mar 28, 2024

Conversation

artlomako
Copy link
Contributor

@artlomako artlomako commented Mar 28, 2024

Change list

  • fix broken KeyEvent

Types of changes

What types of changes are you proposing/introducing to Java client?
Put an x in the boxes that apply

  • No changes in production code.
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Details

After the last change in KeyEvent class, it's impossible to use the key event, because the following code always throws an exception:

  ofNullable(this.keyCode)
                    .map(x -> map.put("keycode", x))
                    .orElseThrow(() -> new IllegalStateException("The key code must be set"));

since map.put() returns null for new key.

Copy link

linux-foundation-easycla bot commented Mar 28, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@@ -19,6 +19,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
Copy link
Contributor

Choose a reason for hiding this comment

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

there is no need for this import

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -83,8 +84,8 @@ public KeyEvent withFlag(KeyEventFlag keyEventFlag) {
*/
public Map<String, Object> build() {
var map = new HashMap<String, Object>();
ofNullable(this.keyCode).map(x -> map.put("keycode", x)).orElseThrow(() -> new IllegalStateException(
Copy link
Contributor

Choose a reason for hiding this comment

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

@valfirst Could there be other places in the source like this one? I assume the issue may have been added during the recent refactoring

Copy link
Collaborator

Choose a reason for hiding this comment

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

yes, this is a regression issue, I've found 2 more similar occurrences, I'll open PR soon

Copy link
Contributor

Choose a reason for hiding this comment

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

thanks. Lets address them all and publish a patch asap

Copy link
Contributor Author

@artlomako artlomako Mar 28, 2024

Choose a reason for hiding this comment

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

@mykola-mokhnach I believe I fixed them in my last commit

Copy link
Collaborator

Choose a reason for hiding this comment

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

I've already addressed AndroidGeoLocation issues here: #2146

@artlomako artlomako changed the title Fix KeyEvent fix: usage of Optional.orElseThrow after Map.put Mar 28, 2024
@valfirst
Copy link
Collaborator

@artlomako checkstyle is failed

@valfirst valfirst merged commit 3dfe243 into appium:master Mar 28, 2024
5 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.

None yet

3 participants