mark JsonTypeCoercer.coerce as nullable - #17802
Conversation
PR Summary by QodoMark JsonTypeCoercer.coerce() as @nullable and harden callers
AI Description
Diagram
High-Level Assessment
Files changed (11)
|
Code Review by Qodo
1.
|
de-facto it can return null. Now IDEA will know it, and show warning for unsafe usages.
| void toTypeReturnsNullForTopLevelJsonNull() { | ||
| String text = new Json().toType("null", String.class); | ||
|
|
||
| assertThat(text).isNull(); |
There was a problem hiding this comment.
1. Nullable assigned to nonnull 🐞 Bug ⚙ Maintainability
In a @NullMarked package, the new test assigns a value it expects to be null into a non-null String, contradicting the nullness contract and triggering nullness-checker/IDE warnings in the test itself.
Agent Prompt
### Issue description
`JsonTest.toTypeReturnsNullForTopLevelJsonNull` assigns a value it asserts is `null` into a non-null `String` within the `org.openqa.selenium.json` package, which is `@NullMarked`.
### Issue Context
This PR’s goal is to surface nullability correctly; tests should follow the same contract to avoid introducing warnings/errors into the build.
### Fix Focus Areas
- java/test/org/openqa/selenium/json/JsonTest.java[170-175]
- java/src/org/openqa/selenium/json/package-info.java[18-21]
### Suggested change
Change `String text = ...` to `@Nullable String text = ...` (or equivalent) so the test matches the intended nullability.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| @Nullable | ||
| private Object coerceValue(Object value, Type type, PropertySetting setting) { | ||
| StringWriter rawJson = new StringWriter(); | ||
| try (JsonOutput output = new JsonOutput(rawJson)) { |
There was a problem hiding this comment.
2. Nullable param typed nonnull 🐞 Bug ≡ Correctness
ConstructorCoercer.coerceValue is now annotated as returning @Nullable, but its value parameter remains non-null even though callers pass properties.get(...) which can be null, creating a nullness-contract violation and warnings under @NullMarked.
Agent Prompt
### Issue description
`coerceValue` can be invoked with `null` (when the JSON map contains a key with a `null` value), but its signature requires a non-null `Object value`.
### Issue Context
This is in `org.openqa.selenium.json` which is `@NullMarked`, so unannotated parameters are non-null by default. The body already handles `null` correctly by writing it as JSON and re-coercing.
### Fix Focus Areas
- java/src/org/openqa/selenium/json/ConstructorCoercer.java[233-242]
- java/src/org/openqa/selenium/json/ConstructorCoercer.java[285-293]
### Suggested change
Update the signature to `private Object coerceValue(@Nullable Object value, Type type, PropertySetting setting)` (keeping the existing `@Nullable` return annotation).
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
|
Code review by qodo was updated up to the latest commit 50d4a85 |
de-facto it can return null. Now IDEA will know it, and show warning for unsafe usages.
🔗 Related Issues
Fixes #14291
🤖 AI assistance
🔄 Types of changes