Repository navigation
fix: seeAlsoDefault NPE when @type is missing #4037
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -350,6 +350,22 @@ public T readObject(JSONReader jsonReader, Type fieldType, Object fieldName, lon | |||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if (object == null && seeAlsoDefault != null && seeAlsoDefault != Void.class) { | ||||||||||||||||||||||||||
| ObjectReader defaultReader = jsonReader.getContext().getObjectReader(seeAlsoDefault); | ||||||||||||||||||||||||||
| if (defaultReader != null) { | ||||||||||||||||||||||||||
| object = (T) defaultReader.createInstance(jsonReader.getContext().getFeatures() | features); | ||||||||||||||||||||||||||
| if (object != null && fieldValues != null) { | ||||||||||||||||||||||||||
| for (Map.Entry<Long, Object> entry : fieldValues.entrySet()) { | ||||||||||||||||||||||||||
| FieldReader fieldReader = defaultReader.getFieldReader(entry.getKey()); | ||||||||||||||||||||||||||
|
Comment on lines
+357
to
+359
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Suggestion] The field-value application loop is unreachable dead code. When
Suggested change
Consider removing this dead loop entirely (keeping only the — qwen3.8-max-preview via Qwen Code /review |
||||||||||||||||||||||||||
| if (fieldReader != null) { | ||||||||||||||||||||||||||
| fieldReader.accept(object, entry.getValue()); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| fieldValues = null; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if (fieldValues != null) { | ||||||||||||||||||||||||||
| for (Map.Entry<Long, Object> entry : fieldValues.entrySet()) { | ||||||||||||||||||||||||||
| FieldReader fieldReader = getFieldReader(entry.getKey()); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Suggestion] The
createInstancefallback — the only live code in this new block — has zero test coverage. BecauseSupportAutoTypeis hardcoded in the reader's features, the autoType branch diverts every field and returns early whenseeAlsoDefaultis set. This block is only reachable when the JSON object is empty ({}), and no existing test parses{}against aseeAlsoDefault-annotated type. Mutation: delete the entire 16-line block and all tests still pass green. — Failure scenario: a regression removing this fallback would causeJSON.parseObject("{}", IAnimal.class)to silently returnnullinstead of a default instance, with no test to catch it.Suggested test:
— qwen3.8-max-preview via Qwen Code /review