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

Updated IllegalArgumentException to NullPointerException for Null Values in Require Class #11162

Merged
merged 6 commits into from
Oct 26, 2022

Conversation

vinoth959
Copy link
Contributor

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.

Update IllegalArgumentException to NullPointerException for Null Values.

Description

Updated IllegalArgumentException to NullPointerException for Null Values in Require.java file.
Changed MustBeSet to MustBePositive for one condition based on the action in the Require class.

Motivation and Context

Misleading Exception and cause issues in debugging.

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.

Updated IllegalArgumentException to NullPointerException for Null Values.
Changed MustBeSet to MustBePositive for one condition based on the action in Require Class.

Update IllegealStateException to NullPointerException as the exception misleads in debugging.
@CLAassistant
Copy link

CLAassistant commented Oct 24, 2022

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@diemol diemol left a comment

Choose a reason for hiding this comment

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

Can you please share the motivation for this pull request? The goal of Require is to check if the arguments passed are valid or not, and checking for nulls is a subset of those validations.

@vinoth959
Copy link
Contributor Author

Hi,

I was getting error as Input should be Set for the nonNull method and could not identify the root cause of the issue and took a while for figuring out that the value is null. Method name says nonNull and it throws illegalargumentexception. Atleast the exception should be null or the message should say the value is null. That is the reason for this pull request

Thanks,
Vinoth

@diemol
Copy link
Member

diemol commented Oct 24, 2022

Hi,

I was getting error as Input should be Set for the nonNull method and could not identify the root cause of the issue and took a while for figuring out that the value is null. Method name says nonNull and it throws illegalargumentexception. Atleast the exception should be null or the message should say the value is null. That is the reason for this pull request

Thanks, Vinoth

Can you share the code that caused you to get that exception?

@vinoth959
Copy link
Contributor Author

vinoth959 commented Oct 24, 2022

i was doing creating new webdriverwait but did not realize the driver passed in the class was null. When i run the code i got illegalargumentexception with Input must be set error and did not have clue on what's happening. On further investigation i found the mistake but that error was confusing. This is just a cosmetic change i'm proposing..

I was passing the wait as below.
waitforElementtoLoad(element, new WebDriverWait(driver, Duration.ofSeconds(3)));

@titusfortner
Copy link
Member

looks like everything that doesn't include MUST_BE_SET can swallow the fact that the value was null:

  public static Duration nonNegative(String argName, Duration arg) {
    if (arg == null) {
      throw new IllegalArgumentException(String.format( , argName));
    }
...

It would make sense for some of these to be more clear what the problem is, but I don't think everything should be changed to NullPointerException

@vinoth959
Copy link
Contributor Author

Got it.. just my thoughts.. if not needed also fine.. I know the problem now.

@vinoth959
Copy link
Contributor Author

I strongly beleive this method should be fixed atleast.

    throw new IllegalArgumentException(String.format(MUST_BE_POSITIVE, argName)); should be        throw new IllegalArgumentException(String.format(MUST_BE_SET, message));

public static double positive(String argName, Double number, String message) {
if (number <= 0) {
if (message == null) {
throw new IllegalArgumentException(String.format(MUST_BE_POSITIVE, argName));
} else {
throw new IllegalArgumentException(message);
}
}
return number;
}

@titusfortner
Copy link
Member

I was agreeing with you, then I realized I was using a bad example....

The fix that needs to happen is that the logic for

public static double positive(String argName, Double number, String message)

needs to match the logic for

public static int positive(String argName, Integer number, String message)

i.e., the if (number == null) conditional got skipped for some reason.

@vinoth959
Copy link
Contributor Author

I was agreeing with you, then I realized I was using a bad example....

The fix that needs to happen is that the logic for

public static double positive(String argName, Double number, String message)

needs to match the logic for

public static int positive(String argName, Integer number, String message)

i.e., the if (number == null) conditional got skipped for some reason.

I actually understand the logic now.. i was confused.

@vinoth959
Copy link
Contributor Author

Updated the above

I was agreeing with you, then I realized I was using a bad example....
The fix that needs to happen is that the logic for

public static double positive(String argName, Double number, String message)

needs to match the logic for

public static int positive(String argName, Integer number, String message)

i.e., the if (number == null) conditional got skipped for some reason.

I actually understand the logic now.. i was confused.

Updated the above logic in the pull request...

What can i do to make this more readable for null values?? We can leave it as it is?

@titusfortner
Copy link
Member

I think we just have to know that "myValue must be set" indicates that it was null

@titusfortner titusfortner requested a review from diemol October 26, 2022 03:11
Copy link
Member

@diemol diemol left a comment

Choose a reason for hiding this comment

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

Thank you, @vinoth959!

@codecov-commenter
Copy link

Codecov Report

Base: 52.28% // Head: 52.28% // No change to project coverage 👍

Coverage data is based on head (f9bb393) compared to base (851cb0d).
Patch has no changes to coverable lines.

❗ Current head f9bb393 differs from pull request most recent head c220509. Consider uploading reports for the commit c220509 to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##            trunk   #11162   +/-   ##
=======================================
  Coverage   52.28%   52.28%           
=======================================
  Files          81       81           
  Lines        5499     5499           
  Branches      198      198           
=======================================
  Hits         2875     2875           
  Misses       2426     2426           
  Partials      198      198           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@diemol diemol merged commit baba6d1 into SeleniumHQ:trunk Oct 26, 2022
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.

5 participants