mark JsonTypeCoercer.coerce as nullable - #17802
Conversation
PR Summary by QodoAnnotate JsonTypeCoercer.coerce as @nullable and propagate nullability through JSON coercers
AI Description
Diagram
High-Level Assessment
Files changed (10)
|
Code Review by Qodo
Context used✅ Compliance rules (platform):
18 rules 1.
|
| } | ||
|
|
||
| <T> T coerce(JsonInput json, Type typeOfT, PropertySetting setter) { | ||
| @Nullable <T> T coerce(JsonInput json, Type typeOfT, PropertySetting setter) { |
There was a problem hiding this comment.
4. Nullable coerce returned as nonnull 🐞 Bug ≡ Correctness
JsonTypeCoercer.coerce is now @Nullable, but core APIs still return it as non-null (e.g., Json#toType) or dereference it without a non-null assertion (e.g., ConstructorCoercer uses properties.keySet()), which will trigger nullness-checker errors and hides real nullable behavior (JSON null -> Java null).
Agent Prompt
### Issue description
`JsonTypeCoercer.coerce` is now annotated `@Nullable`, but callers like `Json#toType` return the result as non-null and `ConstructorCoercer` dereferences the result without a non-null assertion. This creates inconsistent nullness contracts and will cause IDE/JSpecify warnings (and can propagate unexpected nulls at API boundaries).
### Issue Context
Runtime behavior already allows `coerce` to return null when the JSON token is `null` (for non-Optional targets). The PR now exposes this via annotations, so callers must either:
- accept/annotate nullable returns, or
- enforce non-null with `Require.nonNull(...)` / `Objects.requireNonNull(...)` and throw a domain exception.
### Fix Focus Areas
- java/src/org/openqa/selenium/json/JsonTypeCoercer.java[140-155]
- java/src/org/openqa/selenium/json/Json.java[209-214]
- java/src/org/openqa/selenium/json/ConstructorCoercer.java[57-66]
### Expected fix
Pick one consistent policy per API:
- For `Json#toType(...)`: either change return type to `@Nullable <T> T` (most accurate), or wrap with `Require.nonNull` and throw `JsonException` when JSON is `null`.
- For `ConstructorCoercer`: assert non-null for `properties` (e.g., `Require.nonNull("properties", ...)`) before `properties.keySet()` since this coercer is only invoked for non-null JSON objects.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
de-facto it can return null. Now IDEA will know it, and show warning for unsafe usages.
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