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] Enhance Null Check in Exception Handling #14810

Merged
merged 3 commits into from
Dec 4, 2024

Conversation

iampopovich
Copy link
Contributor

@iampopovich iampopovich commented Nov 26, 2024

User description

Thanks for contributing to Selenium!
A PR well described will help maintainers to quickly review and merge it

Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, help reviewers by making them as simple and short as possible.

Description

i've just replaced raw check for null value with java 8 Objects static method requireNonNullElseGet

Motivation and Context

Just to have more standard methods from the language's standard library in the code, making it simpler and free of extra logic.

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

  • Enhanced null checking by replacing raw checks with Objects.requireNonNullElseGet in the Require class.
  • Simplified the logic for throwing exceptions when a number is not positive.
  • Improved code readability and maintainability by using standard library methods.

Changes walkthrough 📝

Relevant files
Enhancement
Require.java
Use `Objects.requireNonNullElseGet` for null checks in Require.java

java/src/org/openqa/selenium/internal/Require.java

  • Replaced raw null checks with Objects.requireNonNullElseGet.
  • Simplified exception throwing logic for positive number checks.
  • +4/-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:

    ⏱️ Estimated effort to review: 1 🔵⚪⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Code Behavior
    Verify that Objects.requireNonNullElseGet has identical behavior to the previous null check implementation, especially around exception message handling

    Copy link
    Contributor

    PR Code Suggestions ✨

    No code suggestions found for the PR.

    @iampopovich iampopovich changed the title [java] enhancement for null checking [java] Enhance Null Check in Exception Handling Nov 26, 2024
    @VietND96 VietND96 requested a review from joerg1985 November 27, 2024 06:47
    @pujagani
    Copy link
    Contributor

    We probably consider deprecating and eventually removing the null check methods of the Require class and using the ones available in Java 8 instead throughout out code base.

    Copy link
    Contributor

    @pujagani pujagani left a comment

    Choose a reason for hiding this comment

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

    @iampopovich Thank you!

    @VietND96 VietND96 merged commit 454ae25 into SeleniumHQ:trunk Dec 4, 2024
    22 of 34 checks passed
    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.

    3 participants