Skip to content

[BUG]2.0.58.android5分支上processObjectInputSingleItemArray()函数内部产生空指针 #3770

@doom20082004

Description

@doom20082004

问题描述

在processObjectInputSingleItemArray()函数中,修复https://github.com/alibaba/fastjson2/issues/1971问题时,2.0.58.android5分支没有正确修复。

环境信息

  • OS信息: macOS 15.6.1 (24G90)
  • JDK信息:1.8.0
  • 版本信息:2.0.58.android5

重现步骤

    protected T processObjectInputSingleItemArray(
            JSONReader jsonReader,
            Type fieldType,
            Object fieldName,
            long features
    ) {
        String message = "expect {, but [, class " + this.typeName;
        if (fieldName != null) {
            message += ", parent fieldName " + fieldName;
        }
        String info = jsonReader.info(message);

        long featuresAll = jsonReader.features(features);
        if ((featuresAll & JSONReader.Feature.SupportSmartMatch.mask) != 0) {
            Type itemType = fieldType == null ? this.objectClass : fieldType;
            List list = jsonReader.readArray(itemType);

            // 对比2.0.58的非安卓分支发现,下面的三行应该删除,不然可能会产生空指针bug
            if (list.size() == 1) {
                return (T) list.get(0);
            }

            if (list != null) {
                if (list.size() == 0) {
                    return null;
                }
                if (list.size() == 1) {
                    return (T) list.get(0);
                }
            }
        }
        throw new JSONException(info);
    }

期待的正确结果

对您期望发生的结果进行清晰简洁的描述。

相关日志输出

请复制并粘贴任何相关的日志输出。

附加信息

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixed

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions