Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Comment on lines +353 to +354

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[Suggestion] The createInstance fallback — the only live code in this new block — has zero test coverage. Because SupportAutoType is hardcoded in the reader's features, the autoType branch diverts every field and returns early when seeAlsoDefault is set. This block is only reachable when the JSON object is empty ({}), and no existing test parses {} against a seeAlsoDefault-annotated type. Mutation: delete the entire 16-line block and all tests still pass green. — Failure scenario: a regression removing this fallback would cause JSON.parseObject("{}", IAnimal.class) to silently return null instead of a default instance, with no test to catch it.

Suggested change
if (object == null && seeAlsoDefault != null && seeAlsoDefault != Void.class) {
ObjectReader defaultReader = jsonReader.getContext().getObjectReader(seeAlsoDefault);
if (object == null && seeAlsoDefault != null && seeAlsoDefault != Void.class) {
ObjectReader defaultReader = jsonReader.getContext().getObjectReader(seeAlsoDefault);

Suggested test:

@Test
public void exceptUseSeeAlsoDefaultEmptyObject() {
    IAnimal animal = JSON.parseObject("{}", IAnimal.class);
    assertEquals(Dog.class, animal.getClass());
}

— qwen3.8-max-preview via Qwen Code /review

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[Suggestion] The field-value application loop is unreachable dead code. When seeAlsoDefault is set, the autoType branch condition at line ~248 is always true (the constructor hardcodes SupportAutoType.mask into features), so every field enters the type-discrimination branch and the method returns early from within the loop. fieldValues is therefore always null when this block is reached — the inner loop never executes. — Concrete cost: a developer reading this code would believe field values are applied during the seeAlsoDefault fallback, but they never are. The dead code adds misleading complexity for future maintainers.

Suggested change
if (object != null && fieldValues != null) {
for (Map.Entry<Long, Object> entry : fieldValues.entrySet()) {
FieldReader fieldReader = defaultReader.getFieldReader(entry.getKey());
if (object != null && fieldValues != null) {
for (Map.Entry<Long, Object> entry : fieldValues.entrySet()) {
FieldReader fieldReader = defaultReader.getFieldReader(entry.getKey());
if (fieldReader != null) {
fieldReader.accept(object, entry.getValue());
}
}
fieldValues = null;
}

Consider removing this dead loop entirely (keeping only the createInstance call), or adding a comment explaining the precondition under which fieldValues would be non-null here.

— 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());
Expand Down
Loading