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

[java] Add nullness for interactions #15095

Merged
merged 1 commit into from
Jan 15, 2025

Conversation

mk868
Copy link
Contributor

@mk868 mk868 commented Jan 15, 2025

User description

Description

In this PR I'm adding nullness annotations for classes:

  • org.openqa.selenium.interactions.Encodable
  • org.openqa.selenium.interactions.InputSource
  • org.openqa.selenium.interactions.KeyInput
  • org.openqa.selenium.interactions.PointerInput

NullAway analysis: #14421

Motivation and Context

The JSpecify nullness annotations will give developers better exposure to potential problems with their code to avoid NullPointerExceptions.
Related issue: #14291

Types of changes

  • Bug fix (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 change)

Checklist

  • I have read the contributing document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

PR Type

Enhancement


Description

  • Added JSpecify @NullMarked annotations to key interaction classes.

  • Introduced @Nullable annotations for nullable parameters and fields.

  • Enhanced null-safety and IDE/static analysis compatibility.

  • Improved code interoperability with Kotlin through nullness annotations.


Changes walkthrough 📝

Relevant files
Enhancement
Encodable.java
Add `@NullMarked` to `Encodable` interface                             

java/src/org/openqa/selenium/interactions/Encodable.java

  • Added @NullMarked annotation to the interface.
  • Improved null-safety for the Encodable interface.
  • +2/-0     
    InputSource.java
    Add `@NullMarked` to `InputSource` interface                         

    java/src/org/openqa/selenium/interactions/InputSource.java

  • Added @NullMarked annotation to the interface.
  • Enhanced null-safety for the InputSource interface.
  • +3/-0     
    KeyInput.java
    Add nullness annotations to `KeyInput` class                         

    java/src/org/openqa/selenium/interactions/KeyInput.java

  • Added @NullMarked annotation to the class.
  • Marked constructor parameter name as @Nullable.
  • Improved null-safety for KeyInput class.
  • +4/-1     
    PointerInput.java
    Add nullness annotations to `PointerInput` class                 

    java/src/org/openqa/selenium/interactions/PointerInput.java

  • Added @NullMarked annotation to the class.
  • Marked constructor parameter name as @Nullable.
  • Marked several fields in PointerEventProperties as @Nullable.
  • Enhanced null-safety for PointerInput and its nested class.
  • +13/-10 

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    🎫 Ticket compliance analysis ✅

    14291 - Fully compliant

    Compliant requirements:

    • Add JSpecify Nullness annotations to Selenium framework code
    • Specify which parameters and return values can be null
    • Make nullness information transparent to IDEs and static code analyzers
    • Improve interoperability with Kotlin
    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Validation Check

    The constructor accepts nullable name parameter but doesn't validate 'kind' parameter before using it with Require.nonNull. Consider moving the validation before using the parameter.

    public PointerInput(Kind kind, @Nullable String name) {
      this.kind = Require.nonNull("Kind of pointer device", kind);
      this.name = Optional.ofNullable(name).orElse(UUID.randomUUID().toString());
    }

    Copy link
    Contributor

    PR Code Suggestions ✨

    No code suggestions found for the PR.

    @mk868
    Copy link
    Contributor Author

    mk868 commented Jan 15, 2025

    Fixed NullAway errors:

    java/src/org/openqa/selenium/interactions/PointerInput.java:286: error: [NullAway] assigning @Nullable expression to @NonNull field
        private Float width = null;
                      ^
        (see http://t.uber.com/nullaway )
    java/src/org/openqa/selenium/interactions/PointerInput.java:287: error: [NullAway] assigning @Nullable expression to @NonNull field
        private Float height = null;
                      ^
        (see http://t.uber.com/nullaway )
    java/src/org/openqa/selenium/interactions/PointerInput.java:288: error: [NullAway] assigning @Nullable expression to @NonNull field
        private Float pressure = null;
                      ^
        (see http://t.uber.com/nullaway )
    java/src/org/openqa/selenium/interactions/PointerInput.java:289: error: [NullAway] assigning @Nullable expression to @NonNull field
        private Float tangentialPressure = null;
                      ^
        (see http://t.uber.com/nullaway )
    java/src/org/openqa/selenium/interactions/PointerInput.java:290: error: [NullAway] assigning @Nullable expression to @NonNull field
        private Integer tiltX = null;
                        ^
        (see http://t.uber.com/nullaway )
    java/src/org/openqa/selenium/interactions/PointerInput.java:291: error: [NullAway] assigning @Nullable expression to @NonNull field
        private Integer tiltY = null;
                        ^
        (see http://t.uber.com/nullaway )
    java/src/org/openqa/selenium/interactions/PointerInput.java:292: error: [NullAway] assigning @Nullable expression to @NonNull field
        private Integer twist = null;
                        ^
        (see http://t.uber.com/nullaway )
    java/src/org/openqa/selenium/interactions/PointerInput.java:293: error: [NullAway] assigning @Nullable expression to @NonNull field
        private Float altitudeAngle = null;
                      ^
        (see http://t.uber.com/nullaway )
    java/src/org/openqa/selenium/interactions/PointerInput.java:294: error: [NullAway] assigning @Nullable expression to @NonNull field
        private Float azimuthAngle = null;
                      ^
        (see http://t.uber.com/nullaway )
    

    @diemol diemol merged commit dbe3f27 into SeleniumHQ:trunk Jan 15, 2025
    33 of 34 checks passed
    @mk868 mk868 deleted the jspecify-interactions branch January 16, 2025 09:44
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    2 participants