Closed iampopovich closed 3 months ago
β±οΈ Estimated effort to review: 2 π΅π΅βͺβͺβͺ |
π§ͺ No relevant tests |
π No security concerns identified |
β‘ No key issues to review |
Category | Suggestion | Score |
Possible bug |
Add a null check to prevent potential NullPointerException___ **Consider checking fornull before using the instanceof pattern to avoid potential NullPointerException . This is a safeguard in case the equals method is called with a null argument.**
[java/src/org/openqa/selenium/By.java [162]](https://github.com/SeleniumHQ/selenium/pull/14315/files#diff-854cf2c9c399c8699c85f72d95e00cad282a9aacecc851cab5ab59c404acde13R162-R162)
```diff
-if (!(o instanceof By that)) {
+if (o == null || !(o instanceof By that)) {
return false;
}
```
- [ ] **Apply this suggestion**
Suggestion importance[1-10]: 10Why: Adding a null check before using the `instanceof` pattern is crucial to prevent potential NullPointerException, which is a common safeguard in equals methods. | 10 |
Add a type check for
___
**Ensure that the | 10 | |
Best practice |
Use
___
**Consider using | 8 |
The build target is still Java 11. I don't remember. Do these code changes work in Java 11?
If target is still java 11 let's close this pr - it's incompatible with java 11 @diemol Thank you for the clarification.
We plan to bump to 17 early next year.
Thanks,
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
After switching to JDK17 in the project, the use of a shorter instanceof check syntax became available.
Reference: https://docs.oracle.com/en/java/javase/17/language/pattern-matching-instanceof-operator.html
There are quite a few such checks in the code, so I created a small pull request to avoid changing all the files at once.
Motivation and Context
I made changes to utilize the latest language features and to prevent the static analyzer from raising warnings about the possibility of using the compact form.
Types of changes
Checklist
PR Type
Enhancement
Description
By
,Cookie
,Event
,Response
) to use pattern matching forinstanceof
, a feature available in JDK 17.equals
methods.fromJson
method in theResponse
class using pattern matching forinstanceof
.Changes walkthrough π
By.java
Use pattern matching for `instanceof` in `By` class
java/src/org/openqa/selenium/By.java
equals
method to use pattern matching forinstanceof
.Cookie.java
Use pattern matching for `instanceof` in `Cookie` class
java/src/org/openqa/selenium/Cookie.java
equals
method to use pattern matching forinstanceof
.Event.java
Use pattern matching for `instanceof` in `Event` class
java/src/org/openqa/selenium/events/Event.java
equals
method to use pattern matching forinstanceof
.Response.java
Use pattern matching for `instanceof` in `Response` class
java/src/org/openqa/selenium/remote/Response.java
equals
method to use pattern matching forinstanceof
.fromJson
method using pattern matching forinstanceof
.